fix(keygen): correctly load token for validation
Some checks failed
Cadoles/go-http-peering/pipeline/head There was a failure building this commit
Some checks failed
Cadoles/go-http-peering/pipeline/head There was a failure building this commit
This commit is contained in:
49
misc/bash_unit/keygen_test.sh
Normal file
49
misc/bash_unit/keygen_test.sh
Normal file
@ -0,0 +1,49 @@
|
||||
#!/bin/bash
|
||||
|
||||
KEYGEN_BIN=${KEYGEN_BIN:-go run ../../cmd/keygen}
|
||||
|
||||
test_create_key_without_passphrase() {
|
||||
local workspace=$(mktemp -d)
|
||||
|
||||
# Generate a new private key without passphrase
|
||||
local key_path="${workspace}/private.key"
|
||||
KEY_PASSPHRASE= $KEYGEN_BIN -create-key > "${key_path}"
|
||||
}
|
||||
|
||||
test_create_key_with_passphrase() {
|
||||
local workspace=$(mktemp -d)
|
||||
|
||||
# Generate a new private key with passphrase
|
||||
local key_path="${workspace}/private.key"
|
||||
KEY_PASSPHRASE=foobar $KEYGEN_BIN -create-key > "${key_path}"
|
||||
}
|
||||
|
||||
test_verify_token_without_passphrase() {
|
||||
local workspace=$(mktemp -d)
|
||||
|
||||
# Generate a new private key without passphrase
|
||||
local key_path="${workspace}/private.key"
|
||||
KEY_PASSPHRASE= $KEYGEN_BIN -create-key > "${key_path}"
|
||||
|
||||
# Generate a new token
|
||||
local token_path="${workspace}/token.jwt"
|
||||
KEY_PASSPHRASE= $KEYGEN_BIN -create-token -key "${key_path}" > "${token_path}"
|
||||
|
||||
# Verify token
|
||||
KEY_PASSPHRASE= $KEYGEN_BIN -verify-token -key "${key_path}" -token "${token_path}" 1>/dev/null
|
||||
}
|
||||
|
||||
test_verify_token_with_passphrase() {
|
||||
local workspace=$(mktemp -d)
|
||||
|
||||
# Generate a new private key with passphrase
|
||||
local key_path="${workspace}/private.key"
|
||||
KEY_PASSPHRASE=foobar $KEYGEN_BIN -create-key > "${key_path}"
|
||||
|
||||
# Generate a new token
|
||||
local token_path="${workspace}/token.jwt"
|
||||
KEY_PASSPHRASE=foobar $KEYGEN_BIN -create-token -key "${key_path}" > "${token_path}"
|
||||
|
||||
# Verify token
|
||||
KEY_PASSPHRASE=foobar $KEYGEN_BIN -verify-token -key "${key_path}" -token "${token_path}" 1>/dev/null
|
||||
}
|
Reference in New Issue
Block a user