You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

  1. #!/bin/bash
  2. EXE=keys
  3. oneTimeSetUp() {
  4. PASS=qwertyuiop
  5. export TM_HOME=$HOME/.keys_test
  6. rm -rf $TM_HOME
  7. assertTrue $?
  8. }
  9. newKey(){
  10. assertNotNull "keyname required" "$1"
  11. KEYPASS=${2:-qwertyuiop}
  12. KEY=$(echo $KEYPASS | ${EXE} new $1)
  13. assertTrue "created $1" $?
  14. return $?
  15. }
  16. # updateKey <name> <oldkey> <newkey>
  17. updateKey() {
  18. (echo $2; echo $3) | keys update $1 > /dev/null
  19. return $?
  20. }
  21. test00MakeKeys() {
  22. USER=demouser
  23. assertFalse "already user $USER" "${EXE} get $USER"
  24. newKey $USER
  25. assertTrue "no user $USER" "${EXE} get $USER"
  26. # make sure bad password not accepted
  27. assertFalse "accepts short password" "echo 123 | keys new badpass"
  28. }
  29. test01ListKeys() {
  30. # one line plus the number of keys
  31. assertEquals "2" $(keys list | wc -l)
  32. newKey foobar
  33. assertEquals "3" $(keys list | wc -l)
  34. # we got the proper name here...
  35. assertEquals "foobar" $(keys list -o json | jq .[1].name | tr -d \" )
  36. # we get all names in normal output
  37. EXPECTEDNAMES=$(echo demouser; echo foobar)
  38. TEXTNAMES=$(keys list | tail -n +2 | cut -f1)
  39. assertEquals "$EXPECTEDNAMES" "$TEXTNAMES"
  40. # let's make sure the addresses match!
  41. assertEquals "text and json addresses don't match" $(keys list | tail -1 | cut -f3) $(keys list -o json | jq .[1].address | tr -d \")
  42. }
  43. test02updateKeys() {
  44. USER=changer
  45. PASS1=awsedrftgyhu
  46. PASS2=S4H.9j.D9S7hso
  47. PASS3=h8ybO7GY6d2
  48. newKey $USER $PASS1
  49. assertFalse "accepts invalid pass" "updateKey $USER $PASS2 $PASS2"
  50. assertTrue "doesn't update" "updateKey $USER $PASS1 $PASS2"
  51. assertTrue "takes new key after update" "updateKey $USER $PASS2 $PASS3"
  52. }
  53. # load and run these tests with shunit2!
  54. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
  55. . $DIR/shunit2