go-http-peering/misc/bash_unit/keygen_test.sh

49 lines
1.5 KiB
Bash

#!/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
}