Created
November 26, 2021 20:09
-
-
Save mayankchoubey/d74d78735e4a3669425dbb2c1a012af9 to your computer and use it in GitHub Desktop.
Deno content server - medium course - section 3 authorize UT
This file contains hidden or 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
| import { authorize } from "../authService.ts"; | |
| import { assert, assertExists } from "https://deno.land/std/testing/asserts.ts"; | |
| Deno.test("No headers", async () => { | |
| const headers = new Headers(); | |
| const ret = authorize(headers); | |
| assertExists(ret); | |
| assert(ret === false); | |
| }); | |
| Deno.test("Empty authorization header", async () => { | |
| const headers = new Headers({ | |
| "Authorization": "", | |
| }); | |
| const ret = authorize(headers); | |
| assertExists(ret); | |
| assert(ret === false); | |
| }); | |
| Deno.test("Authorization header without key", async () => { | |
| const headers = new Headers({ | |
| "Authorization": "Bearer", | |
| }); | |
| const ret = authorize(headers); | |
| assertExists(ret); | |
| assert(ret === false); | |
| }); | |
| Deno.test("wrong api key = fc485dd4-6237-42c3-aad8-a4eeef058239", async () => { | |
| const headers = new Headers({ | |
| "Authorization": "Bearer fc485dd4-6237-42c3-aad8-a4eeef058239", | |
| }); | |
| const ret = authorize(headers); | |
| assertExists(ret); | |
| assert(ret === false); | |
| }); | |
| Deno.test("Correct api key = cba633d4-59f3-42a5-af00-b7430c3a65d8", async () => { | |
| const headers = new Headers({ | |
| "Authorization": "Bearer cba633d4-59f3-42a5-af00-b7430c3a65d8", | |
| }); | |
| const ret = authorize(headers); | |
| assertExists(ret); | |
| assert(ret === true); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment