2022-06-25 22:43:28 +02:00
#shellcheck shell=sh
set -eu
2022-09-12 12:22:48 +02:00
TEST_DIR = " $( mktemp -d) "
DUNITER_PUBSEC_FILE = " ${ TEST_DIR } /duniter.pubsec "
IPFS_PEM_FILE = " ${ TEST_DIR } /ipfs.pem "
gpg( ) {
GNUPGHOME = " ${ TEST_DIR } " command gpg " $@ "
}
2022-06-25 22:43:28 +02:00
keygen( ) {
if [ -x ./keygen ] ; then
2022-09-12 12:22:48 +02:00
GNUPGHOME = " ${ TEST_DIR } " ./keygen " $@ "
2022-06-25 22:43:28 +02:00
elif [ -x ./bin/keygen ] ; then
2022-09-12 12:22:48 +02:00
GNUPGHOME = " ${ TEST_DIR } " ./bin/keygen " $@ "
2022-06-25 22:43:28 +02:00
else
2022-09-12 12:22:48 +02:00
GNUPGHOME = " ${ TEST_DIR } " command keygen " $@ "
2022-06-25 22:43:28 +02:00
fi
}
Describe 'Dependency'
2022-08-31 18:01:15 +02:00
Describe 'pinentry:'
It 'is available'
When run pinentry --help
2022-09-12 12:22:48 +02:00
The output should include 'pinentry'
2022-08-31 18:01:15 +02:00
The status should be success
The stderr should be present
End
End
2022-06-25 22:43:28 +02:00
Describe 'python3:'
It 'is available'
When run python3 --help
2022-09-12 12:22:48 +02:00
The output should include 'python3'
2022-06-25 22:43:28 +02:00
The status should be success
The stderr should equal ""
End
End
End
Describe 'keygen'
Describe '--help:'
It 'prints help'
When run keygen --help
The output should include 'usage:'
The status should be success
The stderr should equal ""
End
End
Describe '--version:'
It 'prints version'
When run keygen --version
2022-09-12 14:19:05 +02:00
The output should include 'v0.0.2'
2022-06-25 22:43:28 +02:00
The status should be success
The stderr should equal ""
End
End
2022-09-12 14:19:05 +02:00
Describe 'username password:'
It 'prints base58 public key for user "username" with password "password"'
When run keygen username password
The output should include '4YLU1xQ9jzb7LzC6d91VZrYTEKS9N2j93Nnvcee6wxZG'
The status should be success
The stderr should equal ""
End
End
Describe '-p username password:'
It 'prints prefixed base58 public key for user "username" with password "password"'
When run keygen -p username password
The output should include 'pub: 4YLU1xQ9jzb7LzC6d91VZrYTEKS9N2j93Nnvcee6wxZG'
The status should be success
The stderr should equal ""
End
End
Describe '-s username password:'
It 'prints base58 secret key for user "username" with password "password"'
When run keygen -s username password
The output should include 'K5heSX4xGUPtRbxcZh6zbgaKbDv8FeVc9JuSNWtUs7C1oGNKqv7kQJ3DHdouTPzoW4duKKnuLQK8LbHKfN9fkjC'
The status should be success
The stderr should equal ""
End
End
Describe '-ps username password:'
It 'prints prefixed base58 secret key for user "username" with password "password"'
When run keygen -ps username password
The output should include 'sec: K5heSX4xGUPtRbxcZh6zbgaKbDv8FeVc9JuSNWtUs7C1oGNKqv7kQJ3DHdouTPzoW4duKKnuLQK8LbHKfN9fkjC'
The status should be success
The stderr should equal ""
End
End
Describe '-k username password:'
It 'prints base58 public and secret keys for user "username" with password "password"'
When run keygen -k username password
The output should include '4YLU1xQ9jzb7LzC6d91VZrYTEKS9N2j93Nnvcee6wxZG'
The output should include 'K5heSX4xGUPtRbxcZh6zbgaKbDv8FeVc9JuSNWtUs7C1oGNKqv7kQJ3DHdouTPzoW4duKKnuLQK8LbHKfN9fkjC'
The status should be success
The stderr should equal ""
End
End
Describe '-pk username password:'
It 'prints prefixed base58 public and secret keys for user "username" with password "password"'
When run keygen -pk username password
The output should include 'pub: 4YLU1xQ9jzb7LzC6d91VZrYTEKS9N2j93Nnvcee6wxZG'
The output should include 'sec: K5heSX4xGUPtRbxcZh6zbgaKbDv8FeVc9JuSNWtUs7C1oGNKqv7kQJ3DHdouTPzoW4duKKnuLQK8LbHKfN9fkjC'
The status should be success
The stderr should equal ""
End
End
Describe '-t duniter -pk username password:'
It 'prints prefixed duniter public key for user "username" with password "password"'
When run keygen -t duniter -pk username password
2022-06-25 22:43:28 +02:00
The output should include 'pub: 4YLU1xQ9jzb7LzC6d91VZrYTEKS9N2j93Nnvcee6wxZG'
The output should include 'sec: K5heSX4xGUPtRbxcZh6zbgaKbDv8FeVc9JuSNWtUs7C1oGNKqv7kQJ3DHdouTPzoW4duKKnuLQK8LbHKfN9fkjC'
The status should be success
The stderr should equal ""
End
End
2022-09-12 12:22:48 +02:00
Describe " -o ${ DUNITER_PUBSEC_FILE } -t duniter username password: "
rm -f " ${ DUNITER_PUBSEC_FILE } "
2022-09-12 14:19:05 +02:00
It 'writes duniter keys to file for user "username" with password "password"'
2022-09-12 12:22:48 +02:00
When run keygen -o " ${ DUNITER_PUBSEC_FILE } " -t duniter username password
The path " ${ DUNITER_PUBSEC_FILE } " should exist
The contents of file " ${ DUNITER_PUBSEC_FILE } " should include 'pub: 4YLU1xQ9jzb7LzC6d91VZrYTEKS9N2j93Nnvcee6wxZG'
The contents of file " ${ DUNITER_PUBSEC_FILE } " should include 'sec: K5heSX4xGUPtRbxcZh6zbgaKbDv8FeVc9JuSNWtUs7C1oGNKqv7kQJ3DHdouTPzoW4duKKnuLQK8LbHKfN9fkjC'
2022-06-25 22:43:28 +02:00
The status should be success
The stderr should equal ""
End
End
2022-09-12 14:19:05 +02:00
Describe " -i ${ DUNITER_PUBSEC_FILE } -t ipfs -pk: "
It 'prints prefixed ipfs keys for duniter keys read in pubsec file'
When run keygen -i " ${ DUNITER_PUBSEC_FILE } " -t ipfs -pk
2022-06-25 22:43:28 +02:00
The output should include 'PeerID: 12D3KooWDMhdm5yrvtrbkshXFjkqLedHieUnPioczy9wzdnzquHC'
The output should include 'PrivKEY: CAESQA+XqCWjRqCjNe9oU3QA796bEH+T+rxgyPQ/EkXvE2MvNJoTbvcP+m51+XwxrmWqHaOpI1ZD0USwLjqAmV8Boas='
The status should be success
The stderr should equal ""
End
End
2022-09-12 12:22:48 +02:00
Describe " -i ${ DUNITER_PUBSEC_FILE } -o ${ IPFS_PEM_FILE } -t ipfs: "
2022-06-25 22:43:28 +02:00
It 'writes ipfs keys to file for duniter keys read in pubsec file'
2022-09-12 12:22:48 +02:00
When run keygen -i " ${ DUNITER_PUBSEC_FILE } " -o " ${ IPFS_PEM_FILE } " -t ipfs
The path " ${ IPFS_PEM_FILE } " should exist
The contents of file " ${ IPFS_PEM_FILE } " should include '-----BEGIN PRIVATE KEY-----'
The contents of file " ${ IPFS_PEM_FILE } " should include 'MC4CAQAwBQYDK2VwBCIEIA+XqCWjRqCjNe9oU3QA796bEH+T+rxgyPQ/EkXvE2Mv'
The contents of file " ${ IPFS_PEM_FILE } " should include '-----END PRIVATE KEY-----'
2022-06-25 22:43:28 +02:00
The status should be success
The stderr should equal ""
End
2022-09-12 12:22:48 +02:00
rm -f " ${ DUNITER_PUBSEC_FILE } " " ${ IPFS_PEM_FILE } "
2022-06-25 22:43:28 +02:00
End
Describe '-t ipfs username password:'
2022-09-12 14:19:05 +02:00
It 'prints ipfs public key for user "username" with password "password"'
2022-06-25 22:43:28 +02:00
When run keygen -t ipfs username password
2022-09-12 14:19:05 +02:00
The output should include '12D3KooWDMhdm5yrvtrbkshXFjkqLedHieUnPioczy9wzdnzquHC'
The status should be success
The stderr should equal ""
End
End
Describe '-t ipfs -s username password:'
It 'prints ipfs secret key for user "username" with password "password"'
When run keygen -t ipfs -s username password
The output should include 'CAESQA+XqCWjRqCjNe9oU3QA796bEH+T+rxgyPQ/EkXvE2MvNJoTbvcP+m51+XwxrmWqHaOpI1ZD0USwLjqAmV8Boas='
The status should be success
The stderr should equal ""
End
End
Describe '-t ipfs -k username password:'
It 'prints ipfs keys for user "username" with password "password"'
When run keygen -t ipfs -k username password
The output should include '12D3KooWDMhdm5yrvtrbkshXFjkqLedHieUnPioczy9wzdnzquHC'
The output should include 'CAESQA+XqCWjRqCjNe9oU3QA796bEH+T+rxgyPQ/EkXvE2MvNJoTbvcP+m51+XwxrmWqHaOpI1ZD0USwLjqAmV8Boas='
The status should be success
The stderr should equal ""
End
End
Describe '-t ipfs -pk username password:'
It 'prints prefixed ipfs keys for user "username" with password "password"'
When run keygen -t ipfs -pk username password
2022-06-25 22:43:28 +02:00
The output should include 'PeerID: 12D3KooWDMhdm5yrvtrbkshXFjkqLedHieUnPioczy9wzdnzquHC'
The output should include 'PrivKEY: CAESQA+XqCWjRqCjNe9oU3QA796bEH+T+rxgyPQ/EkXvE2MvNJoTbvcP+m51+XwxrmWqHaOpI1ZD0USwLjqAmV8Boas='
The status should be success
The stderr should equal ""
End
End
2022-09-12 12:22:48 +02:00
Describe " -o ${ IPFS_PEM_FILE } -t ipfs username password: "
2022-09-12 14:19:05 +02:00
It 'writes ipfs keys to file for user "username" with password "password"'
2022-09-12 12:22:48 +02:00
When run keygen username password -o " ${ IPFS_PEM_FILE } " -t ipfs
The path " ${ IPFS_PEM_FILE } " should exist
The contents of file " ${ IPFS_PEM_FILE } " should include '-----BEGIN PRIVATE KEY-----'
The contents of file " ${ IPFS_PEM_FILE } " should include 'MC4CAQAwBQYDK2VwBCIEIA+XqCWjRqCjNe9oU3QA796bEH+T+rxgyPQ/EkXvE2Mv'
The contents of file " ${ IPFS_PEM_FILE } " should include '-----END PRIVATE KEY-----'
2022-06-25 22:43:28 +02:00
The status should be success
The stderr should equal ""
End
2022-09-12 12:22:48 +02:00
rm -f " ${ IPFS_PEM_FILE } "
2022-06-25 22:43:28 +02:00
End
Describe '-t pgp username password birthday:'
2022-08-28 23:26:59 +02:00
gpg --batch --import --quiet specs/username.asc
gpg --batch --import --quiet specs/username_protected.asc
It 'creates a password protected gpg key for user username'
2022-06-25 22:43:28 +02:00
Skip "You should implement it !"
2022-08-28 23:26:59 +02:00
When run keygen -t pgp username password birthday
2022-06-25 22:43:28 +02:00
The status should be success
End
End
2022-09-12 14:19:05 +02:00
Describe '-g -t duniter -pk username:'
It 'prints prefixed duniter keys for gpg key matching "username"'
When run keygen -g -t duniter -pk username
2022-06-25 22:43:28 +02:00
The output should include 'pub: 2g5UL2zhkn5i7oNYDpWo3fBuWvRYVU1AbMtdVmnGzPNv'
The output should include 'sec: 5WtYFfA26nTfG496gAKhkrLYUMMnwXexmE1E8Q7PvtQEyscHfirsdMzW34zDp7WEkt3exNEVwoG4ajZYrm62wpi2'
The status should be success
The stderr should equal ""
End
End
2022-09-12 14:19:05 +02:00
Describe '-g -t duniter -pk username@protected password:'
It 'prints prefixed duniter keys for gpg key matching "username@protected" locked with "password"'
When run keygen -g -t duniter -pk username@protected password
2022-08-28 23:26:59 +02:00
The output should include 'pub: C1cRu7yb5rZhsmRHQkeZxusAhtYYJypcnXpY3HycEKsU'
The output should include 'sec: VWaEdDroSCoagJDsBnDNUtXJtKAJYdqL6XKNiomz8DtiyF44FvpiMmhidXt2j8HhDBKPZ67xBGcZPnj4Myk6cB8'
The status should be success
The stderr should equal ""
End
End
2022-09-12 14:19:05 +02:00
Describe '-g -t ipfs -pk username:'
It 'prints prefixed ipfs keys for gpg key matching "username"'
When run keygen -g -t ipfs -pk username
2022-06-25 22:43:28 +02:00
The output should include 'PeerID: 12D3KooWBVSe5AaQwgMCXgsxrRG8pTGk1FUBXA5eYxFeskwAtL6r'
The output should include 'PrivKEY: CAESQOHXwPgzoiDca1ZnvhU/W3zdogZXulkoErnUsqt+ut82GN5k4MIbVvz2m6Vq0ij9fQFPNUz+ZZdv2D31K6mzBQc='
The status should be success
The stderr should equal ""
End
End
2022-09-12 14:19:05 +02:00
Describe '-g -t ipfs -pk username@protected password:'
It 'prints prefixed ipfs keys for gpg key matching "username@protected" locked with "password"'
When run keygen -g -t ipfs -pk username@protected password
2022-08-28 23:26:59 +02:00
The output should include 'PeerID: 12D3KooWLpybeFZJGkqCHevi3MPujhx1CDbBLfu6k8BZRH8W8GbQ'
The output should include 'PrivKEY: CAESQBiV+XnBNnryoeBs6SNj9e7Cd9Xj6INn24wyxxacylYqo5idwBHJto4Vbbp6NQzuUF+e7aCmrCf6y+BSyL42/i8='
The status should be success
The stderr should equal ""
End
End
2022-09-12 12:22:48 +02:00
Describe " -g -o ${ DUNITER_PUBSEC_FILE } -t duniter username: "
2022-09-12 14:19:05 +02:00
It 'writes duniter keys to file for gpg key matching "username"'
2022-09-12 12:22:48 +02:00
When run keygen -g -o " ${ DUNITER_PUBSEC_FILE } " -t duniter username
The path " ${ DUNITER_PUBSEC_FILE } " should exist
The contents of file " ${ DUNITER_PUBSEC_FILE } " should include 'pub: 2g5UL2zhkn5i7oNYDpWo3fBuWvRYVU1AbMtdVmnGzPNv'
The contents of file " ${ DUNITER_PUBSEC_FILE } " should include 'sec: 5WtYFfA26nTfG496gAKhkrLYUMMnwXexmE1E8Q7PvtQEyscHfirsdMzW34zDp7WEkt3exNEVwoG4ajZYrm62wpi2'
2022-06-25 22:43:28 +02:00
The status should be success
The stderr should equal ""
End
2022-09-12 12:22:48 +02:00
rm -f " ${ DUNITER_PUBSEC_FILE } "
2022-06-25 22:43:28 +02:00
End
2022-09-12 12:22:48 +02:00
Describe " -g -o ${ DUNITER_PUBSEC_FILE } -t duniter username@protected password: "
2022-09-12 14:19:05 +02:00
It 'writes duniter keys to file for gpg key matching "username@protected" locked with "password"'
2022-09-12 12:22:48 +02:00
When run keygen -g -o " ${ DUNITER_PUBSEC_FILE } " -t duniter username@protected password
The path " ${ DUNITER_PUBSEC_FILE } " should exist
The contents of file " ${ DUNITER_PUBSEC_FILE } " should include 'pub: C1cRu7yb5rZhsmRHQkeZxusAhtYYJypcnXpY3HycEKsU'
The contents of file " ${ DUNITER_PUBSEC_FILE } " should include 'sec: VWaEdDroSCoagJDsBnDNUtXJtKAJYdqL6XKNiomz8DtiyF44FvpiMmhidXt2j8HhDBKPZ67xBGcZPnj4Myk6cB8'
2022-08-28 23:26:59 +02:00
The status should be success
The stderr should equal ""
End
2022-09-12 12:22:48 +02:00
rm -f " ${ DUNITER_PUBSEC_FILE } "
2022-08-28 23:26:59 +02:00
End
2022-09-12 12:22:48 +02:00
Describe " -g -o ${ IPFS_PEM_FILE } -t ipfs username: "
2022-09-12 14:19:05 +02:00
It 'writes ipfs keys to file for gpg key matching "username"'
2022-09-12 12:22:48 +02:00
When run keygen -g -o " ${ IPFS_PEM_FILE } " -t ipfs username
The path " ${ IPFS_PEM_FILE } " should exist
The contents of file " ${ IPFS_PEM_FILE } " should include '-----BEGIN PRIVATE KEY-----'
The contents of file " ${ IPFS_PEM_FILE } " should include 'MC4CAQAwBQYDK2VwBCIEIOHXwPgzoiDca1ZnvhU/W3zdogZXulkoErnUsqt+ut82'
The contents of file " ${ IPFS_PEM_FILE } " should include '-----END PRIVATE KEY-----'
2022-06-25 22:43:28 +02:00
The status should be success
The stderr should equal ""
End
2022-09-12 12:22:48 +02:00
rm -f " ${ IPFS_PEM_FILE } "
2022-06-25 22:43:28 +02:00
End
2022-09-12 12:22:48 +02:00
Describe " -g -o ${ IPFS_PEM_FILE } -t ipfs username@protected password: "
2022-09-12 14:19:05 +02:00
It 'writes ipfs keys to file for gpg key matching "username@protected" locked with "password"'
2022-09-12 12:22:48 +02:00
When run keygen -g -o " ${ IPFS_PEM_FILE } " -t ipfs username@protected password
The path " ${ IPFS_PEM_FILE } " should exist
The contents of file " ${ IPFS_PEM_FILE } " should include '-----BEGIN PRIVATE KEY-----'
The contents of file " ${ IPFS_PEM_FILE } " should include 'MC4CAQAwBQYDK2VwBCIEIBiV+XnBNnryoeBs6SNj9e7Cd9Xj6INn24wyxxacylYq'
The contents of file " ${ IPFS_PEM_FILE } " should include '-----END PRIVATE KEY-----'
2022-08-28 23:26:59 +02:00
The status should be success
The stderr should equal ""
End
2022-09-12 12:22:48 +02:00
rm -f " ${ IPFS_PEM_FILE } "
2022-08-28 23:26:59 +02:00
End
gpg --batch --delete-secret-and-public-key --yes 4D1CDB77E91FFCD81B10F9A7079E5BF4721944FB
gpg --batch --delete-secret-and-public-key --yes 6AF574897D4979B7956AC31B6222A29CBC31A087
2022-06-25 22:43:28 +02:00
End
2022-09-12 12:22:48 +02:00
rm -rf " ${ TEST_DIR } "