Skip to content
Myr

credential.test.ts

This file

Path

apps/platform/test/credential.test.ts

54 lines · 1.7 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–54why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import { Option } from "effect";34import { credentialOf } from "../src/credential.ts";56const token = "alice-token-0123456789abcdef01234567";78const authorized = (authorization: string) => new Headers({ authorization });910const basic = (user: string, password: string) =>11 `Basic ${btoa(`${user}:${password}`)}`;1213describe("the credential a request carries", () => {14 it("is a bearer token", () => {15 expect(credentialOf(authorized(`Bearer ${token}`))).toStrictEqual(16 Option.some(token)17 );18 });1920 it("is git's basic-auth password, whatever the user name", () => {21 expect(credentialOf(authorized(basic("alice", token)))).toStrictEqual(22 Option.some(token)23 );24 expect(25 credentialOf(authorized(basic("x-access-token", token)))26 ).toStrictEqual(Option.some(token));27 });2829 it("keeps a colon inside the password", () => {30 expect(credentialOf(authorized(basic("alice", "a:b")))).toStrictEqual(31 Option.some("a:b")32 );33 });3435 it("is none when the header is absent", () => {36 expect(credentialOf(new Headers())).toStrictEqual(Option.none());37 });3839 it("is none when the header is malformed", () => {40 expect(credentialOf(authorized("Bearer"))).toStrictEqual(Option.none());41 expect(credentialOf(authorized("Basic not*base64"))).toStrictEqual(42 Option.none()43 );44 expect(credentialOf(authorized(`Basic ${btoa("no-colon")}`))).toStrictEqual(45 Option.none()46 );47 expect(credentialOf(authorized(basic("alice", "")))).toStrictEqual(48 Option.none()49 );50 expect(credentialOf(authorized(`Token ${token}`))).toStrictEqual(51 Option.none()52 );53 });54});