Skip to content

Commit

Permalink
Merge pull request #10 from muzzammilshahid/change-required-to-args
Browse files Browse the repository at this point in the history
Change required flags to Args in cryptosign auth
  • Loading branch information
muzzammilshahid authored Jun 28, 2024
2 parents 640293f + 34a7496 commit bcefc98
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
10 changes: 5 additions & 5 deletions cmd/wampproto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ func parseCmd(args []string) (*cmd, error) {
generateChallenge: cryptoSignCommand.Command("generate-challenge", "Generate a cryptosign challenge."),

signChallenge: signChallengeCommand,
challenge: signChallengeCommand.Flag("challenge", "Challenge to sign.").Required().String(),
privateKey: signChallengeCommand.Flag("private-key", "Private key to sign challenge.").Required().String(),
challenge: signChallengeCommand.Arg("challenge", "Challenge to sign.").Required().String(),
privateKey: signChallengeCommand.Arg("private-key", "Private key to sign challenge.").Required().String(),

verifySignature: verifySignatureCommand,
signature: verifySignatureCommand.Flag("signature", "Signature to verify.").Required().String(),
publicKey: verifySignatureCommand.Flag("public-key", "Public key to verify signature.").Required().String(),
signature: verifySignatureCommand.Arg("signature", "Signature to verify.").Required().String(),
publicKey: verifySignatureCommand.Arg("public-key", "Public key to verify signature.").Required().String(),

generateKeyPair: cryptoSignCommand.Command("keygen", "Generate a WAMP cryptosign ed25519 keypair."),

getPublicKey: getPubKeyCommand,
privateKeyFlag: getPubKeyCommand.Flag("private-key",
privateKeyFlag: getPubKeyCommand.Arg("private-key",
"The ed25519 private key to derive the corresponding public key.").Required().String(),
},

Expand Down
30 changes: 13 additions & 17 deletions cmd/wampproto/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestRunSignCryptoSignChallenge(t *testing.T) {
)

t.Run("OutputHex", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign sign-challenge --challenge %s --private-key %s --output hex",
command := fmt.Sprintf("cmd auth cryptosign sign-challenge %s %s --output hex",
testChallenge, testHexPrivateKey)
output, err := main.Run(strings.Split(command, " "))
require.NoError(t, err)
Expand All @@ -55,7 +55,7 @@ func TestRunSignCryptoSignChallenge(t *testing.T) {
})

t.Run("OutputBase64", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign sign-challenge --challenge %s --private-key %s --output base64",
command := fmt.Sprintf("cmd auth cryptosign sign-challenge %s %s --output base64",
testChallenge, testHexPrivateKey)
output, err := main.Run(strings.Split(command, " "))
require.NoError(t, err)
Expand All @@ -65,7 +65,7 @@ func TestRunSignCryptoSignChallenge(t *testing.T) {
})

t.Run("Base64PrivateKey", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign sign-challenge --challenge %s --private-key %s --output hex",
command := fmt.Sprintf("cmd auth cryptosign sign-challenge %s %s --output hex",
testChallenge, testBase64PrivateKey)
output, err := main.Run(strings.Split(command, " "))
require.NoError(t, err)
Expand All @@ -75,7 +75,7 @@ func TestRunSignCryptoSignChallenge(t *testing.T) {
})

t.Run("InvalidPrivateKey", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign sign-challenge --challenge %s --private-key %s --output hex",
command := fmt.Sprintf("cmd auth cryptosign sign-challenge %s %s --output hex",
testChallenge, "mcbhagcakjhfcvsjvcjhvcjhv")
_, err := main.Run(strings.Split(command, " "))
require.Error(t, err)
Expand All @@ -91,29 +91,25 @@ func TestRunVerifyCryptoSignSignature(t *testing.T) {
)

t.Run("HexPublicKey", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign verify-signature --signature %s --public-key %s",
testSignature, testHexPublicKey)
command := fmt.Sprintf("cmd auth cryptosign verify-signature %s %s", testSignature, testHexPublicKey)
output, err := main.Run(strings.Split(command, " "))
wampprotocli.NoErrorEqual(t, err, "Signature verified successfully", output)

})

t.Run("Base64PublicKey", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign verify-signature --signature %s --public-key %s",
testSignature, testBase64PublicKey)
command := fmt.Sprintf("cmd auth cryptosign verify-signature %s %s", testSignature, testBase64PublicKey)
output, err := main.Run(strings.Split(command, " "))
wampprotocli.NoErrorEqual(t, err, "Signature verified successfully", output)
})

t.Run("InvalidPublicKey", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign verify-signature --signature %s --public-key %s",
testSignature, "ivalidPubKey")
command := fmt.Sprintf("cmd auth cryptosign verify-signature %s %s", testSignature, "ivalidPubKey")
_, err := main.Run(strings.Split(command, " "))
require.EqualError(t, err, "invalid public-key: must be of length 32")
})

t.Run("BadSignature", func(t *testing.T) {
command := fmt.Sprintf("cmd auth cryptosign verify-signature --signature %s --public-key %s",
command := fmt.Sprintf("cmd auth cryptosign verify-signature %s %s",
"34806bbdefe1d37c495d4f2c0d27d334155ab2cb244779ea2bddae92b4f3382036b9b519f3285e68a87f7468"+
"8cbf20ed72dbbaae2381e8a3cf023127bf24d1004bb64ae4ddf4e7d841f9194fd0771b81bbf9c90bac56b369dd5d73a311dba691",
testBase64PublicKey)
Expand Down Expand Up @@ -175,37 +171,37 @@ func TestGenerateCryptoSignKeypair(t *testing.T) {
)

t.Run("OutputHex", func(t *testing.T) {
command := fmt.Sprintf("wampproto auth cryptosign get-pubkey --private-key %s --output hex", testPrivateKey)
command := fmt.Sprintf("wampproto auth cryptosign get-pubkey %s --output hex", testPrivateKey)
output, err := main.Run(strings.Split(command, " "))
require.NoError(t, err)

require.Equal(t, testPublicKey, output)
})

t.Run("OutputBase64", func(t *testing.T) {
command := fmt.Sprintf("wampproto auth cryptosign get-pubkey --private-key %s --output base64", testPrivateKey)
command := fmt.Sprintf("wampproto auth cryptosign get-pubkey %s --output base64", testPrivateKey)
output, err := main.Run(strings.Split(command, " "))
require.NoError(t, err)

require.Equal(t, testPublicKeyBase64, output)
})

t.Run("Base64PrivateKey", func(t *testing.T) {
command := fmt.Sprintf("wampproto auth cryptosign get-pubkey --private-key %s --output hex", testPrivateKeyBase64)
command := fmt.Sprintf("wampproto auth cryptosign get-pubkey %s --output hex", testPrivateKeyBase64)
output, err := main.Run(strings.Split(command, " "))
require.NoError(t, err)

require.Equal(t, testPublicKey, output)
})

t.Run("InvalidPrivateKeyFormat", func(t *testing.T) {
command := "wampproto auth cryptosign get-pubkey --private-key invalidString --output base64"
command := "wampproto auth cryptosign get-pubkey invalidString --output base64"
_, err := main.Run(strings.Split(command, " "))
require.EqualError(t, err, "invalid private-key: must be in either hexadecimal or base64 format")
})

t.Run("InvalidPrivateKey", func(t *testing.T) {
command := "wampproto auth cryptosign get-pubkey --private-key 48656c6c6f20576f726c64 --output base64"
command := "wampproto auth cryptosign get-pubkey 48656c6c6f20576f726c64 --output base64"

require.Panics(t, func() {
_, _ = main.Run(strings.Split(command, " "))
Expand Down

0 comments on commit bcefc98

Please sign in to comment.