|
@@ -61,7 +61,7 @@ type args struct {
|
|
|
|
|
|
|
|
type want struct {
|
|
type want struct {
|
|
|
Path string `json:"path,omitempty"`
|
|
Path string `json:"path,omitempty"`
|
|
|
- Body string `json:"body,omitempty"`
|
|
|
|
|
|
|
+ Body *string `json:"body,omitempty"`
|
|
|
Err string `json:"err,omitempty"`
|
|
Err string `json:"err,omitempty"`
|
|
|
Result string `json:"result,omitempty"`
|
|
Result string `json:"result,omitempty"`
|
|
|
ResultMap map[string]string `json:"resultmap,omitempty"`
|
|
ResultMap map[string]string `json:"resultmap,omitempty"`
|
|
@@ -364,7 +364,22 @@ func TestWebhookGetSecret(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var testCasesPushSecret = `
|
|
var testCasesPushSecret = `
|
|
|
-case: good json
|
|
|
|
|
|
|
+---
|
|
|
|
|
+case: secret key not found
|
|
|
|
|
+args:
|
|
|
|
|
+ url: /api/pushsecret?id={{ .remoteRef.remoteKey }}&secret={{ .remoteRef.secretKey }}
|
|
|
|
|
+ key: testkey
|
|
|
|
|
+ secretkey: not-found
|
|
|
|
|
+ pushsecret: true
|
|
|
|
|
+ secret:
|
|
|
|
|
+ name: test-secret
|
|
|
|
|
+ data:
|
|
|
|
|
+ secretkey: value
|
|
|
|
|
+want:
|
|
|
|
|
+ path: /api/pushsecret?id=testkey&secret=not-found
|
|
|
|
|
+ err: 'failed to find secret key in secret with key: not-found'
|
|
|
|
|
+---
|
|
|
|
|
+case: default body good json
|
|
|
args:
|
|
args:
|
|
|
url: /api/pushsecret?id={{ .remoteRef.remoteKey }}&secret={{ .remoteRef.secretKey }}
|
|
url: /api/pushsecret?id={{ .remoteRef.remoteKey }}&secret={{ .remoteRef.secretKey }}
|
|
|
key: testkey
|
|
key: testkey
|
|
@@ -376,26 +391,59 @@ args:
|
|
|
secretkey: value
|
|
secretkey: value
|
|
|
want:
|
|
want:
|
|
|
path: /api/pushsecret?id=testkey&secret=secretkey
|
|
path: /api/pushsecret?id=testkey&secret=secretkey
|
|
|
|
|
+ body: 'value'
|
|
|
err: ''
|
|
err: ''
|
|
|
---
|
|
---
|
|
|
-case: secret key not found
|
|
|
|
|
|
|
+case: good json
|
|
|
args:
|
|
args:
|
|
|
url: /api/pushsecret?id={{ .remoteRef.remoteKey }}&secret={{ .remoteRef.secretKey }}
|
|
url: /api/pushsecret?id={{ .remoteRef.remoteKey }}&secret={{ .remoteRef.secretKey }}
|
|
|
key: testkey
|
|
key: testkey
|
|
|
- secretkey: not-found
|
|
|
|
|
|
|
+ body: 'pre {{ .remoteRef.remoteKey }} {{ .remoteRef.testkey }} post'
|
|
|
|
|
+ secretkey: secretkey
|
|
|
pushsecret: true
|
|
pushsecret: true
|
|
|
secret:
|
|
secret:
|
|
|
name: test-secret
|
|
name: test-secret
|
|
|
data:
|
|
data:
|
|
|
secretkey: value
|
|
secretkey: value
|
|
|
want:
|
|
want:
|
|
|
- path: /api/pushsecret?id=testkey&secret=not-found
|
|
|
|
|
- err: 'failed to find secret key in secret with key: not-found'
|
|
|
|
|
|
|
+ path: /api/pushsecret?id=testkey&secret=secretkey
|
|
|
|
|
+ body: 'pre testkey value post'
|
|
|
|
|
+ err: ''
|
|
|
|
|
+---
|
|
|
|
|
+case: empty body
|
|
|
|
|
+args:
|
|
|
|
|
+ url: /api/pushsecret?id={{ .remoteRef.remoteKey }}
|
|
|
|
|
+ key: testkey
|
|
|
|
|
+ body: '{{ "" }}'
|
|
|
|
|
+ pushsecret: true
|
|
|
|
|
+ secret:
|
|
|
|
|
+ name: test-secret
|
|
|
|
|
+ data:
|
|
|
|
|
+ secretkey: value
|
|
|
|
|
+want:
|
|
|
|
|
+ path: /api/pushsecret?id=testkey
|
|
|
|
|
+ body: ''
|
|
|
|
|
+ err: ''
|
|
|
|
|
+---
|
|
|
|
|
+case: default body pushing without secret key
|
|
|
|
|
+args:
|
|
|
|
|
+ url: /api/pushsecret?id={{ .remoteRef.remoteKey }}
|
|
|
|
|
+ key: testkey
|
|
|
|
|
+ pushsecret: true
|
|
|
|
|
+ secret:
|
|
|
|
|
+ name: test-secret
|
|
|
|
|
+ data:
|
|
|
|
|
+ secretkey: value
|
|
|
|
|
+want:
|
|
|
|
|
+ path: /api/pushsecret?id=testkey
|
|
|
|
|
+ body: '{"secretkey":"value"}'
|
|
|
|
|
+ err: ''
|
|
|
---
|
|
---
|
|
|
case: pushing without secret key
|
|
case: pushing without secret key
|
|
|
args:
|
|
args:
|
|
|
url: /api/pushsecret?id={{ .remoteRef.remoteKey }}
|
|
url: /api/pushsecret?id={{ .remoteRef.remoteKey }}
|
|
|
key: testkey
|
|
key: testkey
|
|
|
|
|
+ body: 'pre {{ .remoteRef.remoteKey }} {{ index (.remoteRef.testkey | fromJson) "secretkey" }} post'
|
|
|
pushsecret: true
|
|
pushsecret: true
|
|
|
secret:
|
|
secret:
|
|
|
name: test-secret
|
|
name: test-secret
|
|
@@ -403,8 +451,23 @@ args:
|
|
|
secretkey: value
|
|
secretkey: value
|
|
|
want:
|
|
want:
|
|
|
path: /api/pushsecret?id=testkey
|
|
path: /api/pushsecret?id=testkey
|
|
|
|
|
+ body: 'pre testkey value post'
|
|
|
err: ''
|
|
err: ''
|
|
|
---
|
|
---
|
|
|
|
|
+case: pushing without secret key with dynamic resolution
|
|
|
|
|
+args:
|
|
|
|
|
+ url: /api/pushsecret?id={{ .remoteRef.remoteKey }}
|
|
|
|
|
+ key: testkey
|
|
|
|
|
+ body: 'pre {{ .remoteRef.remoteKey }} {{ index (index .remoteRef .remoteRef.remoteKey | fromJson) "secretkey" }} post'
|
|
|
|
|
+ pushsecret: true
|
|
|
|
|
+ secret:
|
|
|
|
|
+ name: test-secret
|
|
|
|
|
+ data:
|
|
|
|
|
+ secretkey: value
|
|
|
|
|
+want:
|
|
|
|
|
+ path: /api/pushsecret?id=testkey
|
|
|
|
|
+ body: 'pre testkey value post'
|
|
|
|
|
+ err: ''
|
|
|
`
|
|
`
|
|
|
|
|
|
|
|
func TestWebhookPushSecret(t *testing.T) {
|
|
func TestWebhookPushSecret(t *testing.T) {
|
|
@@ -427,10 +490,10 @@ func testCaseServer(tc testCase, t *testing.T) *httptest.Server {
|
|
|
if tc.Want.Path != "" && req.URL.String() != tc.Want.Path {
|
|
if tc.Want.Path != "" && req.URL.String() != tc.Want.Path {
|
|
|
t.Errorf("%s: unexpected api path: %s, expected %s", tc.Case, req.URL.String(), tc.Want.Path)
|
|
t.Errorf("%s: unexpected api path: %s, expected %s", tc.Case, req.URL.String(), tc.Want.Path)
|
|
|
}
|
|
}
|
|
|
- if tc.Want.Body != "" {
|
|
|
|
|
|
|
+ if tc.Want.Body != nil {
|
|
|
b, _ := io.ReadAll(req.Body)
|
|
b, _ := io.ReadAll(req.Body)
|
|
|
- if string(b) != tc.Want.Body {
|
|
|
|
|
- t.Errorf("%s: unexpected body: %s, expected %s", tc.Case, string(b), tc.Want.Body)
|
|
|
|
|
|
|
+ if tc.Want.Body != nil && string(b) != *tc.Want.Body {
|
|
|
|
|
+ t.Errorf("%s: unexpected body: %s, expected %s", tc.Case, string(b), *tc.Want.Body)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if tc.Args.StatusCode != 0 {
|
|
if tc.Args.StatusCode != 0 {
|