forked from swagger-api/swagger-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(oath): for authorization bearer (swagger-api#7936)
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
test/e2e-cypress/static/documents/features/auth-bearer-flow.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: Bearer auth test | ||
version: 1.0.0 | ||
servers: | ||
# - url: https://httpbin.org # live external url | ||
- url: http://localhost:3231 # will need to mock | ||
paths: | ||
/get: | ||
get: | ||
responses: | ||
'200': | ||
description: ok | ||
security: | ||
- bearerAuth: [] | ||
components: | ||
securitySchemes: | ||
bearerAuth: | ||
type: http | ||
scheme: bearer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
describe("OAuth2 Bearer flow", () => { | ||
beforeEach(() => { | ||
const staticResponse = { | ||
statusCode: 200, | ||
body: { | ||
name: "not a random secret for test", | ||
} | ||
} | ||
cy.intercept("GET", "/get*", staticResponse).as( | ||
"tokenRequest" | ||
) | ||
}) | ||
|
||
it("should be focused on input field with aria-label", () => { | ||
cy.visit( | ||
"/?url=/documents/features/auth-bearer-flow.yaml" | ||
) | ||
.get("button.authorize") | ||
.click() | ||
cy.focused() | ||
.should("have.attr", "aria-label").and("eq", "auth-bearer-value") | ||
}) | ||
it("should make a header request with proper sample cURL header", () => { | ||
cy.visit( | ||
"/?url=/documents/features/auth-bearer-flow.yaml" | ||
) | ||
.get("button.authorize") | ||
.click() | ||
.get("section > input") | ||
.type("secret_token") | ||
.get(".auth-btn-wrapper > .authorize") | ||
.click() | ||
.get("button.close-modal") | ||
.click() | ||
// Try-it-out | ||
.get("#operations-default-get_get") | ||
.click() | ||
.get(".btn.try-out__btn") | ||
.click() | ||
.get(".btn.execute") | ||
.click() | ||
cy.wait("@tokenRequest") | ||
.its("request") | ||
.its("headers") | ||
.its("authorization") | ||
.should("equal", "Bearer secret_token") | ||
.get(".curl") | ||
.contains("Authorization: Bearer secret_token") | ||
.should("be.visible") | ||
}) | ||
}) |