mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Move all public connectors to ce/plugins * Update tooling to account for new go modules under ce * Ensure we test all CE plugins in CI * Move Dummypay to ce/plugins for simplicity's sake in the generation scripts * Use versioned pkg/domain in plugins * Ensure that renovate updates all CE plugins in a single PR when pkg/domain tags are pushed to github * Ensure Justfile commands work over all CE plugins * Copy ce plugin go.mods in dev.Dockerfile * Only add a go.mod for new plugins if they are ce * Ensure generated generic client structs are named correctly for submodule * Add coverprofile for each ce plugin * Add set -e for Justfile for loops over plugins * Infer go version from flake.nix in connector template tool
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package hmac
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestGenerateReturnsSignatureWithKeyId(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
signature := buildSignature("api_key", "api_secret", "", date())
|
|
expectedPrefix := "Signature keyId=\"api_key\","
|
|
hasKeyID := strings.HasPrefix(signature, expectedPrefix)
|
|
assert.True(t, hasKeyID, "HMAC signature must contain the keyId")
|
|
}
|
|
|
|
func TestGenerateReturnsSignatureWithAlgorithm(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
signature := buildSignature("api_key", "api_secret", "", date())
|
|
expectedAlgorithm := "algorithm=\"hmac-sha1\","
|
|
actualValue := signature[26:48]
|
|
assert.Equal(t, expectedAlgorithm, actualValue, "HMAC signature must contain the algorithm used")
|
|
}
|
|
|
|
func TestGenerateReturnsSignatureWithHeaders(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
signature := buildSignature("api_key", "api_secret", "", date())
|
|
expectedHeaders := "headers=\"date x-mod-nonce\","
|
|
actualValue := signature[48:75]
|
|
assert.Equal(t, expectedHeaders, actualValue, "HMAC signature must contain the headers")
|
|
}
|
|
|
|
func TestGenerateReturnsSignatureWithSignatureValue(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
signature := buildSignature("api_key", "api_secret", "", date())
|
|
expectedSignature := "signature=\""
|
|
actualValue := signature[75:86]
|
|
assert.Equal(t, expectedSignature, actualValue, "HMAC signature must contain the signature")
|
|
}
|
|
|
|
func TestGenerateReturnsHashedSignature(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
signature := buildSignature("api_key", "api_secret", "", date())
|
|
actualValue := signature[86:117]
|
|
assert.True(t, actualValue != "", "Encoded HMAC signature should be present")
|
|
}
|
|
|
|
func TestGenerateAcceptsANonce(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
signature := buildSignature("api_key", "api_secret", "nonce", date())
|
|
actualValue := signature[86:116]
|
|
expected := "9V8gi5Mp9MsL%2FO7mV6qZlBM9%2FR"
|
|
assert.Equal(t, expected, actualValue, "HMAC signature must contain the signature")
|
|
}
|
|
|
|
func date() string {
|
|
now, _ := time.Parse(time.RFC1123, "Mon, 02 Jan 2020 15:04:05 GMT")
|
|
|
|
return now.String()
|
|
}
|