Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
To be squashed
  • Loading branch information
buger committed Aug 4, 2017
1 parent c15f806 commit 0af5b28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions coprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,22 @@ func TestCoProcessReturnOverrides(t *testing.T) {
}
}

func TestCoProcessReturnOverridesErrorMessage(t *testing.T) {
spec := createSpecTest(t, basicCoProcessDef)
chain := buildCoProcessChain(spec, "hook_test_return_overrides_error", coprocess.HookType_Pre, apidef.MiddlewareDriver("python"))
session := createNonThrottledSession()
spec.SessionManager.UpdateSession("abc", session, 60)

recorder := httptest.NewRecorder()

req := testReq(t, "GET", "/headers", nil)
req.Header.Set("authorization", "abc")
chain.ServeHTTP(recorder, req)
if recorder.Code != 401 || recorder.Body.String() != "custom error message" {
t.Fatal("ReturnOverrides HTTP response is invalid")
}
}

const basicCoProcessDef = `{
"api_id": "1",
"org_id": "default",
Expand Down
5 changes: 5 additions & 0 deletions coprocess_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ func applyTestHooks(objectPtr unsafe.Pointer) {
ResponseCode: 200,
ResponseError: "body",
}
case "hook_test_return_overrides_error":
object.Request.ReturnOverrides = &coprocess.ReturnOverrides{
ResponseCode: 401,
ResponseError: "custom error message",
}
case "hook_test_bad_auth_using_id_extractor":
case "hook_test_bad_auth_cp_error":
case "hook_test_successful_auth":
Expand Down

0 comments on commit 0af5b28

Please sign in to comment.