11import Log from '../src/Log' ;
22import SigninRequest from '../src/SigninRequest' ;
33
4- import StubState from './StubState' ;
5-
64import chai from 'chai' ;
75chai . should ( ) ;
86let assert = chai . assert ;
97
108describe ( "SigninRequest" , function ( ) {
11-
12- let stubState = new StubState ( "state" ) ;
13- let StubStateCtor = ( ) => stubState ;
14-
9+
1510 let subject ;
16-
17- beforeEach ( function ( ) {
18- subject = new SigninRequest ( "http://sts/signin" , "client" , "http://app" , "id_token" , "openid" , undefined , StubStateCtor ) ;
11+ let settings ;
12+
13+ beforeEach ( function ( ) {
14+ settings = { url : "http://sts/signin" ,
15+ client_id : "client" ,
16+ redirect_uri : "http://app" ,
17+ response_type : "id_token" ,
18+ scope : "openid" ,
19+ state : { data : "test" }
20+ } ;
21+ subject = new SigninRequest ( settings ) ;
1922 } ) ;
2023
2124 describe ( "constructor" , function ( ) {
2225
2326 it ( "should require a url param" , function ( ) {
2427 try {
25- new SigninRequest ( undefined , "client" , "http://app" , "id_token" , "openid" ) ;
28+ delete settings . url ;
29+ new SigninRequest ( settings ) ;
2630 }
2731 catch ( e ) {
2832 e . message . should . contain ( 'url' ) ;
@@ -32,7 +36,8 @@ describe("SigninRequest", function() {
3236 } ) ;
3337 it ( "should require a client_id param" , function ( ) {
3438 try {
35- new SigninRequest ( "http://sts/signin" , undefined , "http://app" , "id_token" , "openid" ) ;
39+ delete settings . client_id ;
40+ new SigninRequest ( settings ) ;
3641 }
3742 catch ( e ) {
3843 e . message . should . contain ( 'client_id' ) ;
@@ -42,7 +47,8 @@ describe("SigninRequest", function() {
4247 } ) ;
4348 it ( "should require a redirect_uri param" , function ( ) {
4449 try {
45- new SigninRequest ( "http://sts/signin" , "client" , undefined , "id_token" , "openid" ) ;
50+ delete settings . redirect_uri ;
51+ new SigninRequest ( settings ) ;
4652 }
4753 catch ( e ) {
4854 e . message . should . contain ( 'redirect_uri' ) ;
@@ -52,7 +58,8 @@ describe("SigninRequest", function() {
5258 } ) ;
5359 it ( "should require a response_type param" , function ( ) {
5460 try {
55- new SigninRequest ( "http://sts/signin" , "client" , "http://app" , undefined , "openid" ) ;
61+ delete settings . response_type ;
62+ new SigninRequest ( settings ) ;
5663 }
5764 catch ( e ) {
5865 e . message . should . contain ( 'response_type' ) ;
@@ -62,7 +69,8 @@ describe("SigninRequest", function() {
6269 } ) ;
6370 it ( "should require a scope param" , function ( ) {
6471 try {
65- new SigninRequest ( "http://sts/signin" , "client" , "http://app" , "id_token" , undefined ) ;
72+ delete settings . scope ;
73+ new SigninRequest ( settings ) ;
6674 }
6775 catch ( e ) {
6876 e . message . should . contain ( 'scope' ) ;
@@ -72,7 +80,7 @@ describe("SigninRequest", function() {
7280 } ) ;
7381
7482 } ) ;
75-
83+
7684 describe ( "signinUrl" , function ( ) {
7785
7886 it ( "should include url" , function ( ) {
@@ -91,9 +99,49 @@ describe("SigninRequest", function() {
9199 subject . signinUrl . should . contain ( "scope=openid" ) ;
92100 } ) ;
93101 it ( "should include state" , function ( ) {
94- subject . signinUrl . should . contain ( "state=state" ) ;
102+ subject . signinUrl . should . contain ( "state=" + subject . state . id ) ;
103+ } ) ;
104+
105+ } ) ;
106+
107+ describe ( "isOidc" , function ( ) {
108+ it ( "should indicate if response_type is oidc" , function ( ) {
109+ settings . response_type = "id_token" ;
110+ subject = new SigninRequest ( settings ) ;
111+ subject . isOidc . should . be . true ;
112+
113+ settings . response_type = "id_token token" ;
114+ subject = new SigninRequest ( settings ) ;
115+ subject . isOidc . should . be . true ;
116+
117+ settings . response_type = "token id_token" ;
118+ subject = new SigninRequest ( settings ) ;
119+ subject . isOidc . should . be . true ;
120+
121+ settings . response_type = "token" ;
122+ subject = new SigninRequest ( settings ) ;
123+ subject . isOidc . should . be . false ;
124+ } ) ;
125+ } ) ;
126+
127+ describe ( "isOAuth" , function ( ) {
128+ it ( "should indicate if response_type is oauth" , function ( ) {
129+ settings . response_type = "token" ;
130+ subject = new SigninRequest ( settings ) ;
131+ subject . isOAuth . should . be . true ;
132+
133+ settings . response_type = "id_token token" ;
134+ subject = new SigninRequest ( settings ) ;
135+ subject . isOAuth . should . be . true ;
136+
137+ settings . response_type = "token id_token" ;
138+ subject = new SigninRequest ( settings ) ;
139+ subject . isOAuth . should . be . true ;
140+
141+ settings . response_type = "id_token" ;
142+ subject = new SigninRequest ( settings ) ;
143+ subject . isOAuth . should . be . false ;
95144 } ) ;
96-
97145 } ) ;
98146
99147} ) ;
0 commit comments