Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify BitBucketInterceptor to BitbucketInterceptor #596

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions docs/eventlisteners.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,8 @@ spec:

### Bitbucket Interceptors

Bitbucket Interceptors contain logic to validate and filter webhooks that come from
Bitbucket server or cloud. Supported features include validating webhooks actually came from Bitbucket as well as
filtering incoming events.
The Bitbucket interceptor provides support for hooks originating in [Bitbucket server](https://confluence.atlassian.com/bitbucketserver), providing server hook signature validation and event-filtering.
[Bitbucket cloud](https://support.atlassian.com/bitbucket-cloud/) is not currently supported by this interceptor, as it has no secret validation, so you could match on the incoming requests using the CEL interceptor.

To use this Interceptor as a validator, create a secret string using the method
of your choice, and configure the Bitbucket webhook to use that secret value.
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/triggers/v1alpha1/event_listener_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ type EventInterceptor struct {
GitHub *GitHubInterceptor `json:"github,omitempty"`
GitLab *GitLabInterceptor `json:"gitlab,omitempty"`
CEL *CELInterceptor `json:"cel,omitempty"`
Bitbucket *BitBucketInterceptor `json:"bitbucket,omitempty"`
Bitbucket *BitbucketInterceptor `json:"bitbucket,omitempty"`
}

// WebhookInterceptor provides a webhook to intercept and pre-process events
Expand All @@ -100,8 +100,8 @@ type WebhookInterceptor struct {
Header []v1beta1.Param `json:"header,omitempty"`
}

// BitBucketInterceptor provides a webhook to intercept and pre-process events
type BitBucketInterceptor struct {
// BitbucketInterceptor provides a webhook to intercept and pre-process events
type BitbucketInterceptor struct {
SecretRef *SecretRef `json:"secretRef,omitempty"`
EventTypes []string `json:"eventTypes,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func TestEventListenerValidate_error(t *testing.T) {
Interceptors: []*v1alpha1.EventInterceptor{{
GitHub: &v1alpha1.GitHubInterceptor{},
GitLab: &v1alpha1.GitLabInterceptor{},
Bitbucket: &v1alpha1.BitBucketInterceptor{},
Bitbucket: &v1alpha1.BitbucketInterceptor{},
}},
}},
},
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/triggers/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/interceptors/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import (
type Interceptor struct {
KubeClientSet kubernetes.Interface
Logger *zap.SugaredLogger
Bitbucket *triggersv1.BitBucketInterceptor
Bitbucket *triggersv1.BitbucketInterceptor
EventListenerNamespace string
}

func NewInterceptor(bh *triggersv1.BitBucketInterceptor, k kubernetes.Interface, ns string, l *zap.SugaredLogger) interceptors.Interceptor {
func NewInterceptor(bh *triggersv1.BitbucketInterceptor, k kubernetes.Interface, ns string, l *zap.SugaredLogger) interceptors.Interceptor {
return &Interceptor{
Logger: l,
Bitbucket: bh,
Expand Down
20 changes: 10 additions & 10 deletions pkg/interceptors/bitbucket/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
}
tests := []struct {
name string
Bitbucket *triggersv1.BitBucketInterceptor
Bitbucket *triggersv1.BitbucketInterceptor
args args
want []byte
wantErr bool
}{
{
name: "no secret",
Bitbucket: &triggersv1.BitBucketInterceptor{},
Bitbucket: &triggersv1.BitbucketInterceptor{},
args: args{
payload: ioutil.NopCloser(bytes.NewBufferString("somepayload")),
signature: "foo",
Expand All @@ -59,7 +59,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
},
{
name: "invalid header for secret",
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
SecretRef: &triggersv1.SecretRef{
SecretName: "mysecret",
SecretKey: "token",
Expand All @@ -81,7 +81,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
},
{
name: "valid header for secret",
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
SecretRef: &triggersv1.SecretRef{
SecretName: "mysecret",
SecretKey: "token",
Expand All @@ -106,7 +106,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
},
{
name: "matching event",
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
EventTypes: []string{"pr:opened", "repo:refs_changed"},
},
args: args{
Expand All @@ -118,7 +118,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
},
{
name: "no matching event",
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
EventTypes: []string{"pr:opened", "repo:refs_changed"},
},
args: args{
Expand All @@ -129,7 +129,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
},
{
name: "valid header for secret and matching event",
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
SecretRef: &triggersv1.SecretRef{
SecretName: "mysecret",
SecretKey: "token",
Expand All @@ -156,7 +156,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
},
{
name: "valid header for secret, but no matching event",
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
SecretRef: &triggersv1.SecretRef{
SecretName: "mysecret",
SecretKey: "token",
Expand All @@ -182,7 +182,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
},
{
name: "invalid header for secret, but matching event",
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
SecretRef: &triggersv1.SecretRef{
SecretName: "mysecret",
SecretKey: "token",
Expand All @@ -205,7 +205,7 @@ func TestInterceptor_ExecuteTrigger_Signature(t *testing.T) {
wantErr: true,
}, {
name: "nil body does not panic",
Bitbucket: &triggersv1.BitBucketInterceptor{},
Bitbucket: &triggersv1.BitbucketInterceptor{},
args: args{
payload: nil,
signature: "foo",
Expand Down
4 changes: 2 additions & 2 deletions pkg/sink/sink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ func TestHandleEventWithInterceptorsAndTriggerAuth(t *testing.T) {

}

func TestHandleEventWithBitBucketInterceptors(t *testing.T) {
func TestHandleEventWithBitbucketInterceptors(t *testing.T) {
eventBody := json.RawMessage(`{"repository": {"links": {"clone": [{"href": "testurl", "name": "ssh"}, {"href": "testurl", "name": "http"}]}}, "changes": [{"ref": {"displayId": "test-branch"}}]}`)
tb, tt := getResources(t, "$(body.repository.links.clone[1].href)")

Expand All @@ -924,7 +924,7 @@ func TestHandleEventWithBitBucketInterceptors(t *testing.T) {
Bindings: []*triggersv1.EventListenerBinding{{Name: "tb", Kind: "TriggerBinding"}},
Template: triggersv1.EventListenerTemplate{Name: "tt"},
Interceptors: []*triggersv1.EventInterceptor{{
Bitbucket: &triggersv1.BitBucketInterceptor{
Bitbucket: &triggersv1.BitbucketInterceptor{
SecretRef: &triggersv1.SecretRef{
SecretKey: "secretKey",
SecretName: "secret",
Expand Down