Add the runnable Gitea, PostgreSQL, and Hop control-plane foundation
Hop-State: A_06FN3QYA1N56NQYGZ81DWGR Hop-Proposal: R_06FN3QXJRYPPEQZQA6S69QG Hop-Task: T_06FN3MVGY3MT82ESQ89BND0 Hop-Attempt: AT_06FN3MVGY092BFA5MR9C7EG
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package gitea
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestVerifySignature(t *testing.T) {
|
||||
body := []byte(`{"hello":"hop"}`)
|
||||
mac := hmac.New(sha256.New, []byte("secret"))
|
||||
_, _ = mac.Write(body)
|
||||
signature := hex.EncodeToString(mac.Sum(nil))
|
||||
|
||||
if !VerifySignature(body, signature, "secret") {
|
||||
t.Fatal("expected valid signature")
|
||||
}
|
||||
if VerifySignature(body, signature, "wrong") {
|
||||
t.Fatal("accepted signature with wrong secret")
|
||||
}
|
||||
if VerifySignature(body, "not-hex", "secret") {
|
||||
t.Fatal("accepted malformed signature")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user