1- import { isAuthenticated , init , getAuthKey } from "../../../src/auth/auth.js" ;
1+ import { isAuthenticated , init , getAuthKey , addUnAuthenticatedAPI } from "../../../src/auth/auth.js" ;
22/*global describe, it*/
33
44import * as chai from 'chai' ;
@@ -30,21 +30,27 @@ describe('unit tests for auth module', function () {
3030 const authenticated = isAuthenticated ( {
3131 headers : {
3232 authorization : 'Basic 1'
33+ } , raw : {
34+ url : ""
3335 }
3436
3537 } , { } ) ;
3638 expect ( authenticated ) . eql ( true ) ;
3739 } ) ;
3840 it ( 'isAuthenticated should fail if headers are missing' , function ( ) {
3941 init ( getConfigs ( ) . authKey ) ;
40- const authenticated = isAuthenticated ( { } , { } ) ;
42+ const authenticated = isAuthenticated ( { raw : {
43+ url : ""
44+ } } , { } ) ;
4145 expect ( authenticated ) . eql ( false ) ;
4246 } ) ;
4347 it ( 'isAuthenticated should fail' , function ( ) {
4448 init ( '1' ) ;
4549 const authenticated = isAuthenticated ( {
4650 headers : {
4751 authorization : 'Basic 10'
52+ } , raw : {
53+ url : ""
4854 }
4955
5056 } , { } ) ;
@@ -56,6 +62,8 @@ describe('unit tests for auth module', function () {
5662 const authenticated = isAuthenticated ( {
5763 headers : {
5864 authorization : 'Basic 1 1234'
65+ } , raw : {
66+ url : ""
5967 }
6068
6169 } , { } ) ;
@@ -66,6 +74,8 @@ describe('unit tests for auth module', function () {
6674 const authenticated = isAuthenticated ( {
6775 headers : {
6876 authorization : '123 1'
77+ } , raw : {
78+ url : ""
6979 }
7080
7181 } , { } ) ;
@@ -76,6 +86,35 @@ describe('unit tests for auth module', function () {
7686 const authenticated = isAuthenticated ( {
7787 headers : {
7888 abc : '123'
89+ } , raw : {
90+ url : ""
91+ }
92+
93+ } , { } ) ;
94+ expect ( authenticated ) . eql ( false ) ;
95+ } ) ;
96+
97+ it ( 'addUnAuthenticatedAPI should disable authentication for given api' , function ( ) {
98+ init ( getConfigs ( ) . authKey ) ;
99+ addUnAuthenticatedAPI ( "/testAPI01" ) ;
100+ const authenticated = isAuthenticated ( {
101+ headers : {
102+ abc : '123'
103+ } , raw : {
104+ url : "/testAPI01#43?z=34"
105+ }
106+
107+ } , { } ) ;
108+ expect ( authenticated ) . eql ( true ) ;
109+ } ) ;
110+
111+ it ( 'addUnAuthenticatedAPI should not disable authentication if api signature mismatch with /' , function ( ) {
112+ addUnAuthenticatedAPI ( "/testAPI01" ) ;
113+ const authenticated = isAuthenticated ( {
114+ headers : {
115+ abc : '123'
116+ } , raw : {
117+ url : "/testAPI01/#43?z=34" // note the / at the end of url
79118 }
80119
81120 } , { } ) ;
0 commit comments