Skip to content

Commit

Permalink
bitbucket: unit test for hook secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Jul 5, 2018
1 parent 1bddcba commit c033047
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions scm/driver/bitbucket/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,29 @@ func TestWebhooks(t *testing.T) {
}
}

// func TestWebhookInvalid(t *testing.T) {
// f, _ := ioutil.ReadFile("samples/push.json")
// r, _ := http.NewRequest("GET", "/", bytes.NewBuffer(f))
// r.Header.Set("X-GitHub-Event", "push")
// r.Header.Set("X-GitHub-Delivery", "ee8d97b4-1479-43f1-9cac-fbbd1b80da55")
// r.Header.Set("X-Hub-Signature", "sha1=380f462cd2e160b84765144beabdad2e930a7ec5")

// s := new(webhookService)
// _, err := s.Parse(r, secretFunc)
// if err != scm.ErrSignatureInvalid {
// t.Errorf("Expect invalid signature error, got %v", err)
// }
// }
func TestWebhookInvalid(t *testing.T) {
f, _ := ioutil.ReadFile("testdata/webhooks/push.json")
r, _ := http.NewRequest("GET", "/?secret=xxxxxinvalidxxxxxx", bytes.NewBuffer(f))
r.Header.Set("x-event-key", "repo:push")

s := new(webhookService)
_, err := s.Parse(r, secretFunc)
if err != scm.ErrSignatureInvalid {
t.Errorf("Expect invalid signature error, got %v", err)
}
}

func TestWebhookValidated(t *testing.T) {
f, _ := ioutil.ReadFile("testdata/webhooks/push.json")
r, _ := http.NewRequest("GET", "/?secret=71295b197fa25f4356d2fb9965df3f2379d903d7", bytes.NewBuffer(f))
r.Header.Set("x-event-key", "repo:push")

s := new(webhookService)
_, err := s.Parse(r, secretFunc)
if err != nil {
t.Errorf("Expect valid signature, got %v", err)
}
}

func secretFunc(interface{}) (string, error) {
return "71295b197fa25f4356d2fb9965df3f2379d903d7", nil
Expand Down

0 comments on commit c033047

Please sign in to comment.