From 7b06ac1b7c2fdd6e6abde79e04dcb66bfab25ed2 Mon Sep 17 00:00:00 2001 From: Tim Lai Date: Wed, 23 Mar 2022 14:29:02 -0700 Subject: [PATCH] test(oath): for authorization bearer (#7936) --- .../documents/features/auth-bearer-flow.yaml | 20 ++++++++ .../tests/features/auth-bearer-flow.js | 51 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 test/e2e-cypress/static/documents/features/auth-bearer-flow.yaml create mode 100644 test/e2e-cypress/tests/features/auth-bearer-flow.js diff --git a/test/e2e-cypress/static/documents/features/auth-bearer-flow.yaml b/test/e2e-cypress/static/documents/features/auth-bearer-flow.yaml new file mode 100644 index 00000000..c4fe7c79 --- /dev/null +++ b/test/e2e-cypress/static/documents/features/auth-bearer-flow.yaml @@ -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 diff --git a/test/e2e-cypress/tests/features/auth-bearer-flow.js b/test/e2e-cypress/tests/features/auth-bearer-flow.js new file mode 100644 index 00000000..49ffbaca --- /dev/null +++ b/test/e2e-cypress/tests/features/auth-bearer-flow.js @@ -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") + }) +})