Skip to content

Commit

Permalink
revert: signature extraction in the HMAC strategy (#835)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik authored Nov 4, 2024
1 parent f34ee26 commit 6335f90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions token/hmac/hmacsha.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ func (c *HMACStrategy) validate(ctx context.Context, secret []byte, token string
return nil
}

func (c *HMACStrategy) Signature(token string) string {
_, sig, ok := strings.Cut(token, ".")
if !ok {
func (*HMACStrategy) Signature(token string) string {
split := strings.Split(token, ".")
if len(split) != 2 {
return ""
}
return sig
return split[1]
}

func (c *HMACStrategy) generateHMAC(ctx context.Context, data []byte, key *[32]byte) []byte {
Expand Down
14 changes: 14 additions & 0 deletions token/hmac/hmacsha_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ func TestGenerate(t *testing.T) {
}
}

func TestSignature(t *testing.T) {
cg := HMACStrategy{}

for token, expected := range map[string]string{
"": "",
"foo": "",
"foo.bar": "bar",
"foo.bar.baz": "",
".": "",
} {
assert.Equal(t, expected, cg.Signature(token))
}
}

func TestValidateSignatureRejects(t *testing.T) {
cg := HMACStrategy{
Config: &fosite.Config{GlobalSecret: []byte("1234567890123456789012345678901234567890")},
Expand Down

0 comments on commit 6335f90

Please sign in to comment.