FeaturesTemplatesShowcaseTownie
AI
BlogDocsPricing
Log inSign up
rozek
rozekAuthorization_from_EnvVar_Test
Public
Like
Authorization_from_EnvVar_Test
Home
Code
2
README.md
H
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in miliseconds.
Sign up now
Code
/
Code
/
Search
Open in new tab
README.md

Here are some tests for val Authorization_from_EnvVar

Test Cases

Positive Test Cases

  1. Valid token with defined environment variable

    • EnvVarName: "VALID_TOKEN"
    • Environment variable value: "secret123"
    • Authorization header: "Bearer secret123"
    • Mode: "forbid-if-not-defined"
    • Expected result: true
  2. Valid token with allow-if-not-defined mode

    • EnvVarName: "VALID_TOKEN"
    • Environment variable value: "secret123"
    • Authorization header: "Bearer secret123"
    • Mode: "allow-if-not-defined"
    • Expected result: true
  3. Valid token with missing mode (default behavior)

    • EnvVarName: "VALID_TOKEN"
    • Environment variable value: "secret123"
    • Authorization header: "Bearer secret123"
    • Mode: undefined
    • Expected result: true

Negative Test Cases

  1. Invalid token

    • EnvVarName: "VALID_TOKEN"
    • Environment variable value: "secret123"
    • Authorization header: "Bearer wrongtoken"
    • Mode: "forbid-if-not-defined"
    • Expected result: false
  2. No Authorization header

    • EnvVarName: "VALID_TOKEN"
    • Environment variable value: "secret123"
    • Authorization header: undefined
    • Mode: "forbid-if-not-defined"
    • Expected result: false
  3. Environment variable not defined, forbid mode

    • EnvVarName: "UNDEFINED_TOKEN"
    • Environment variable value: undefined
    • Authorization header: "Bearer anytoken"
    • Mode: "forbid-if-not-defined"
    • Expected result: false
  4. Environment variable not defined, allow mode

    • EnvVarName: "UNDEFINED_TOKEN"
    • Environment variable value: undefined
    • Authorization header: "Bearer anytoken"
    • Mode: "allow-if-not-defined"
    • Expected result: true

Error Cases

  1. Invalid environment variable name

    • EnvVarName: "1INVALID"
    • Environment variable value: "secret123"
    • Authorization header: "Bearer secret123"
    • Mode: "forbid-if-not-defined"
    • Expected result: Error thrown
  2. Invalid Mode

    • EnvVarName: "VALID_TOKEN"
    • Environment variable value: "secret123"
    • Authorization header: "Bearer secret123"
    • Mode: "invalid-mode"
    • Expected result: Error thrown

Edge Cases

  1. Empty string as token

    • EnvVarName: "EMPTY_TOKEN"
    • Environment variable value: ""
    • Authorization header: "Bearer "
    • Mode: "forbid-if-not-defined"
    • Expected result: true
  2. Case-sensitive token comparison

    • EnvVarName: "CASE_TOKEN"
    • Environment variable value: "Secret123"
    • Authorization header: "Bearer secret123"
    • Mode: "forbid-if-not-defined"
    • Expected result: false
  3. Non-Bearer authorization type

    • EnvVarName: "VALID_TOKEN"
    • Environment variable value: "secret123"
    • Authorization header: "Basic secret123"
    • Mode: "forbid-if-not-defined"
    • Expected result: false
Code
README.md
H
main.tsx
Go to top
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Product
FeaturesPricing
Developers
DocsStatusAPI ExamplesNPM Package Examples
Explore
ShowcaseTemplatesNewest ValsTrending ValsNewsletter
Company
AboutBlogCareersBrandhi@val.town
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.