1- import { getUsernameAndPasswordFromAuthBasic } from "../index" ;
1+ import {
2+ getAuthBasicFromUsernameAndPassword ,
3+ getUsernameAndPasswordFromAuthBasic ,
4+ } from '../index'
25
36describe ( 'Get Username and Password From Headers' , ( ) => {
47 it ( 'should throw an error when headers input objet is empty' , ( ) => {
58 const headers = { }
69 const t = ( ) => {
710 getUsernameAndPasswordFromAuthBasic ( headers )
8- } ;
9- expect ( t ) . toThrowError ( 'Invalid or Missing Authorization header' ) ;
10- } ) ;
11+ }
12+ expect ( t ) . toThrowError ( 'Invalid or Missing Authorization header' )
13+ } )
1114 it ( 'should throw an error when headers input objet has not "authorization" or "Authorization" entries' , ( ) => {
12- const headers = { " test" : " value" }
15+ const headers = { test : ' value' }
1316 const t = ( ) => {
1417 getUsernameAndPasswordFromAuthBasic ( headers )
15- } ;
16- expect ( t ) . toThrowError ( ) ;
17- } ) ;
18+ }
19+ expect ( t ) . toThrowError ( )
20+ } )
1821 it ( 'should throw an error when authorization header has not start with "Basic "' , ( ) => {
19- const headers = { authorization : 'test value' }
22+ const headers = { authorization : 'test value' }
2023 const t = ( ) => {
2124 getUsernameAndPasswordFromAuthBasic ( headers )
22- } ;
23- expect ( t ) . toThrowError ( ) ;
24- } ) ;
25+ }
26+ expect ( t ) . toThrowError ( )
27+ } )
2528 it ( 'should throw an error when Authorization header has not start with "Basic "' , ( ) => {
26- const headers = { Authorization : 'test value' }
29+ const headers = { Authorization : 'test value' }
2730 const t = ( ) => {
2831 getUsernameAndPasswordFromAuthBasic ( headers )
29- } ;
30- expect ( t ) . toThrowError ( ) ;
31- } ) ;
32+ }
33+ expect ( t ) . toThrowError ( )
34+ } )
3235 it ( 'should return username and password when authorization header is properly set' , ( ) => {
33- const headers = { authorization : 'Basic dXNlcjp0ZXN0' }
34- expect ( getUsernameAndPasswordFromAuthBasic ( headers ) ) . toEqual ( { username : "user" , password : "test" } )
35- } ) ;
36+ const headers = { authorization : 'Basic dXNlcjp0ZXN0' }
37+ expect ( getUsernameAndPasswordFromAuthBasic ( headers ) ) . toEqual ( {
38+ username : 'user' ,
39+ password : 'test' ,
40+ } )
41+ } )
3642 it ( 'should return username and password when Authorization header is properly set' , ( ) => {
37- const headers = { Authorization : 'Basic dXNlcjp0ZXN0' }
38- expect ( getUsernameAndPasswordFromAuthBasic ( headers ) ) . toEqual ( { username : "user" , password : "test" } )
39- } ) ;
43+ const headers = { Authorization : 'Basic dXNlcjp0ZXN0' }
44+ expect ( getUsernameAndPasswordFromAuthBasic ( headers ) ) . toEqual ( {
45+ username : 'user' ,
46+ password : 'test' ,
47+ } )
48+ } )
4049 it ( 'should return username and password when both authorization Authorization header is properly set' , ( ) => {
41- const headers = { authorization : 'Basic dXNlcjp0ZXN0' , Authorization : 'Basic dXNlcjp0ZXN0' }
42- expect ( getUsernameAndPasswordFromAuthBasic ( headers ) ) . toEqual ( { username : "user" , password : "test" } )
43- } ) ;
44- } ) ;
50+ const headers = {
51+ authorization : 'Basic dXNlcjp0ZXN0' ,
52+ Authorization : 'Basic dXNlcjp0ZXN0' ,
53+ }
54+ expect ( getUsernameAndPasswordFromAuthBasic ( headers ) ) . toEqual ( {
55+ username : 'user' ,
56+ password : 'test' ,
57+ } )
58+ } )
59+ } )
60+
61+ describe ( 'should return b64 string from username and password' , ( ) => {
62+ expect ( getAuthBasicFromUsernameAndPassword ( 'user' , 'test' ) ) . toEqual (
63+ 'Basic dXNlcjp0ZXN0' ,
64+ )
65+ } )
0 commit comments