(t *testing.T)
| 241 | } |
| 242 | |
| 243 | func TestPythonBundles(t *testing.T) { |
| 244 | unused := uuid.NewHex() |
| 245 | |
| 246 | t.Run("Single-file bundle with authentication hook", func(t *testing.T) { |
| 247 | ts := setupGateway() |
| 248 | defer ts.Close() |
| 249 | |
| 250 | validToken := uuid.NewHex() |
| 251 | authCheckBundle := ts.RegisterBundle("python_with_auth_check", pythonBundleWithAuthCheck(validToken, unused)) |
| 252 | |
| 253 | ts.Gw.BuildAndLoadAPI(func(spec *gateway.APISpec) { |
| 254 | spec.Proxy.ListenPath = "/test-api/" |
| 255 | spec.UseKeylessAccess = false |
| 256 | spec.EnableCoProcessAuth = true |
| 257 | spec.CustomMiddlewareBundle = authCheckBundle |
| 258 | spec.VersionData.NotVersioned = true |
| 259 | }, func(spec *gateway.APISpec) { |
| 260 | spec.Proxy.ListenPath = "/test-api-with-customplugin-auth-enabled/" |
| 261 | spec.UseKeylessAccess = false |
| 262 | spec.CustomPluginAuthEnabled = true |
| 263 | spec.CustomMiddlewareBundle = authCheckBundle |
| 264 | spec.VersionData.NotVersioned = true |
| 265 | }) |
| 266 | |
| 267 | validAuth := map[string]string{"Authorization": validToken} |
| 268 | invalidAuth := map[string]string{"Authorization": "invalid_token"} |
| 269 | |
| 270 | ts.Run(t, []test.TestCase{ |
| 271 | {Path: "/test-api/", Code: http.StatusOK, Headers: validAuth}, |
| 272 | {Path: "/test-api/", Code: http.StatusForbidden, Headers: invalidAuth}, |
| 273 | {Path: "/test-api/", Code: http.StatusForbidden, Headers: validAuth}, |
| 274 | |
| 275 | // Delete sessions so that next set of tests works afresh |
| 276 | {Method: http.MethodDelete, Path: "/tyk/keys/" + validToken, AdminAuth: true, Code: http.StatusOK, BodyMatch: `"action":"deleted"`}, |
| 277 | |
| 278 | {Path: "/test-api-with-customplugin-auth-enabled/", Code: http.StatusOK, Headers: validAuth}, |
| 279 | {Path: "/test-api-with-customplugin-auth-enabled/", Code: http.StatusForbidden, Headers: invalidAuth}, |
| 280 | {Path: "/test-api-with-customplugin-auth-enabled/", Code: http.StatusForbidden, Headers: validAuth}, |
| 281 | }...) |
| 282 | }) |
| 283 | |
| 284 | t.Run("Auth with policy", func(t *testing.T) { |
| 285 | ts := setupGateway() |
| 286 | defer ts.Close() |
| 287 | |
| 288 | validToken := uuid.NewHex() |
| 289 | authCheckBundle := ts.RegisterBundle("python_with_auth_check", pythonBundleWithAuthCheck(unused, validToken)) |
| 290 | |
| 291 | specs := ts.Gw.BuildAndLoadAPI(func(spec *gateway.APISpec) { |
| 292 | spec.Auth.AuthHeaderName = "Authorization" |
| 293 | spec.Proxy.ListenPath = "/test-api/" |
| 294 | spec.UseKeylessAccess = false |
| 295 | spec.EnableCoProcessAuth = true |
| 296 | spec.CustomMiddlewareBundle = authCheckBundle |
| 297 | spec.VersionData.NotVersioned = true |
| 298 | }) |
| 299 | |
| 300 | pID := ts.CreatePolicy(func(p *user.Policy) { |
nothing calls this directly
no test coverage detected