Expose the constants in pkg/controller/bootstrap and add a validate token method

This commit is contained in:
Lucas Käldström
2017-02-14 20:29:23 +02:00
parent 8db5ca1fbb
commit 4940c32c39
5 changed files with 46 additions and 19 deletions

View File

@@ -51,3 +51,17 @@ func TestComputeDetachedSig(t *testing.T) {
t.Errorf("Wrong signature. Got: %v", sig)
}
}
func TestDetachedTokenIsValid(t *testing.T) {
// Valid detached JWS token and valid inputs should succeed
sig := "eyJhbGciOiJIUzI1NiIsImtpZCI6Impvc2h1YSJ9..VShe2taLd-YTrmWuRkcL_8QTNDHYxQIEBsAYYiIj1_8"
if !DetachedTokenIsValid(sig, content, id, secret) {
t.Errorf("Content %q and token \"%s:%s\" should equal signature: %q", content, id, secret, sig)
}
// Invalid detached JWS token and valid inputs should fail
sig2 := sig + "foo"
if DetachedTokenIsValid(sig2, content, id, secret) {
t.Errorf("Content %q and token \"%s:%s\" should not equal signature: %q", content, id, secret, sig)
}
}