@@ -2,7 +2,7 @@ package githubhook
2
2
3
3
import (
4
4
"crypto/hmac"
5
- "crypto/sha1 "
5
+ "crypto/sha256 "
6
6
"encoding/hex"
7
7
"fmt"
8
8
"net/http"
@@ -29,11 +29,11 @@ func expectParseError(t *testing.T, msg string, r *http.Request) {
29
29
}
30
30
31
31
func signature (body string ) string {
32
- dst := make ([]byte , 40 )
33
- computed := hmac .New (sha1 .New , []byte (testSecret ))
32
+ dst := make ([]byte , sha256 . Size * 2 )
33
+ computed := hmac .New (sha256 .New , []byte (testSecret ))
34
34
computed .Write ([]byte (body ))
35
35
hex .Encode (dst , computed .Sum (nil ))
36
- return "sha1=" + string (dst )
36
+ return signaturePrefix + string (dst )
37
37
}
38
38
39
39
func TestNonPost (t * testing.T ) {
@@ -48,20 +48,20 @@ func TestMissingSignature(t *testing.T) {
48
48
49
49
func TestMissingEvent (t * testing.T ) {
50
50
r , _ := http .NewRequest ("POST" , "/path" , nil )
51
- r .Header .Add ("x-hub-signature" , "bogus signature" )
51
+ r .Header .Add ("x-hub-signature-256 " , "bogus signature" )
52
52
expectNewError (t , "No event!" , r )
53
53
}
54
54
55
55
func TestMissingEventId (t * testing.T ) {
56
56
r , _ := http .NewRequest ("POST" , "/path" , nil )
57
- r .Header .Add ("x-hub-signature" , "bogus signature" )
57
+ r .Header .Add ("x-hub-signature-256 " , "bogus signature" )
58
58
r .Header .Add ("x-github-event" , "bogus event" )
59
59
expectNewError (t , "No event Id!" , r )
60
60
}
61
61
62
62
func TestInvalidSignature (t * testing.T ) {
63
63
r , _ := http .NewRequest ("POST" , "/path" , strings .NewReader ("..." ))
64
- r .Header .Add ("x-hub-signature" , "bogus signature" )
64
+ r .Header .Add ("x-hub-signature-256 " , "bogus signature" )
65
65
r .Header .Add ("x-github-event" , "bogus event" )
66
66
r .Header .Add ("x-github-delivery" , "bogus id" )
67
67
expectParseError (t , "Invalid signature" , r )
@@ -72,7 +72,7 @@ func TestValidSignature(t *testing.T) {
72
72
body := "{}"
73
73
74
74
r , _ := http .NewRequest ("POST" , "/path" , strings .NewReader (body ))
75
- r .Header .Add ("x-hub-signature" , signature (body ))
75
+ r .Header .Add ("x-hub-signature-256 " , signature (body ))
76
76
r .Header .Add ("x-github-event" , "bogus event" )
77
77
r .Header .Add ("x-github-delivery" , "bogus id" )
78
78
0 commit comments