@@ -18,4 +18,194 @@ describe('Strategy', function() {
1818 } ) ;
1919 } )
2020
21+ describe ( 'constructed with undefined options' , function ( ) {
22+ it ( 'should throw' , function ( ) {
23+ expect ( function ( ) {
24+ var strategy = new GoogleStrategy ( undefined , function ( ) { } ) ;
25+ } ) . to . throw ( Error ) ;
26+ } ) ;
27+ } )
28+
29+ describe ( 'authorization request with documented parameters' , function ( ) {
30+ var strategy = new GoogleStrategy ( {
31+ clientID : 'ABC123' ,
32+ clientSecret : 'secret'
33+ } , function ( ) { } ) ;
34+
35+
36+ var url ;
37+
38+ before ( function ( done ) {
39+ chai . passport . use ( strategy )
40+ . redirect ( function ( u ) {
41+ url = u ;
42+ done ( ) ;
43+ } )
44+ . req ( function ( req ) {
45+ req . session = { } ;
46+ } )
47+ . authenticate ( { prompt : 'select_account' , loginHint : 'john@mail.com' , accessType : 'offline' } ) ;
48+ } ) ;
49+
50+ it ( 'should be redirected' , function ( ) {
51+ expect ( url ) . to . equal ( 'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&prompt=select_account&login_hint=john%40mail.com&response_type=code&redirect_uri=&client_id=ABC123' ) ;
52+ } ) ;
53+ } ) ; // authorization request with documented parameters
54+
55+ describe ( 'authorization request with incremental authorization parameters' , function ( ) {
56+ var strategy = new GoogleStrategy ( {
57+ clientID : 'ABC123' ,
58+ clientSecret : 'secret'
59+ } , function ( ) { } ) ;
60+
61+
62+ var url ;
63+
64+ before ( function ( done ) {
65+ chai . passport . use ( strategy )
66+ . redirect ( function ( u ) {
67+ url = u ;
68+ done ( ) ;
69+ } )
70+ . req ( function ( req ) {
71+ req . session = { } ;
72+ } )
73+ . authenticate ( { scope : [ 'https://www.googleapis.com/auth/drive.file' ] , includeGrantedScopes : true } ) ;
74+ } ) ;
75+
76+ it ( 'should be redirected' , function ( ) {
77+ expect ( url ) . to . equal ( 'https://accounts.google.com/o/oauth2/v2/auth?include_granted_scopes=true&response_type=code&redirect_uri=&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.file&client_id=ABC123' ) ;
78+ } ) ;
79+ } ) ; // authorization request with incremental authorization parameters
80+
81+ describe ( 'authorization request with Google Apps for Work parameters' , function ( ) {
82+ var strategy = new GoogleStrategy ( {
83+ clientID : 'ABC123' ,
84+ clientSecret : 'secret'
85+ } , function ( ) { } ) ;
86+
87+
88+ var url ;
89+
90+ before ( function ( done ) {
91+ chai . passport . use ( strategy )
92+ . redirect ( function ( u ) {
93+ url = u ;
94+ done ( ) ;
95+ } )
96+ . req ( function ( req ) {
97+ req . session = { } ;
98+ } )
99+ . authenticate ( { hostedDomain : 'example.com' } ) ;
100+ } ) ;
101+
102+ it ( 'should be redirected' , function ( ) {
103+ expect ( url ) . to . equal ( 'https://accounts.google.com/o/oauth2/v2/auth?hd=example.com&response_type=code&redirect_uri=&client_id=ABC123' ) ;
104+ } ) ;
105+ } ) ; // authorization request with Google Apps for Work parameters
106+
107+ describe ( 'authorization request with Google Apps for Work parameters, in abbreviated form' , function ( ) {
108+ var strategy = new GoogleStrategy ( {
109+ clientID : 'ABC123' ,
110+ clientSecret : 'secret'
111+ } , function ( ) { } ) ;
112+
113+
114+ var url ;
115+
116+ before ( function ( done ) {
117+ chai . passport . use ( strategy )
118+ . redirect ( function ( u ) {
119+ url = u ;
120+ done ( ) ;
121+ } )
122+ . req ( function ( req ) {
123+ req . session = { } ;
124+ } )
125+ . authenticate ( { hd : 'example.com' } ) ;
126+ } ) ;
127+
128+ it ( 'should be redirected' , function ( ) {
129+ expect ( url ) . to . equal ( 'https://accounts.google.com/o/oauth2/v2/auth?hd=example.com&response_type=code&redirect_uri=&client_id=ABC123' ) ;
130+ } ) ;
131+ } ) ; // authorization request with Google Apps for Work parameters, in abbreviated form
132+
133+ describe ( 'authorization request with Google+ parameters' , function ( ) {
134+ var strategy = new GoogleStrategy ( {
135+ clientID : 'ABC123' ,
136+ clientSecret : 'secret'
137+ } , function ( ) { } ) ;
138+
139+
140+ var url ;
141+
142+ before ( function ( done ) {
143+ chai . passport . use ( strategy )
144+ . redirect ( function ( u ) {
145+ url = u ;
146+ done ( ) ;
147+ } )
148+ . req ( function ( req ) {
149+ req . session = { } ;
150+ } )
151+ . authenticate ( { requestVisibleActions : 'http://schema.org/AddAction http://schema.org/ReviewAction' } ) ;
152+ } ) ;
153+
154+ it ( 'should be redirected' , function ( ) {
155+ expect ( url ) . to . equal ( 'https://accounts.google.com/o/oauth2/v2/auth?request_visible_actions=http%3A%2F%2Fschema.org%2FAddAction%20http%3A%2F%2Fschema.org%2FReviewAction&response_type=code&redirect_uri=&client_id=ABC123' ) ;
156+ } ) ;
157+ } ) ; // authorization request with Google+ parameters
158+
159+ describe ( 'authorization request with OpenID 2.0 migration parameters' , function ( ) {
160+ var strategy = new GoogleStrategy ( {
161+ clientID : 'ABC123' ,
162+ clientSecret : 'secret'
163+ } , function ( ) { } ) ;
164+
165+
166+ var url ;
167+
168+ before ( function ( done ) {
169+ chai . passport . use ( strategy )
170+ . redirect ( function ( u ) {
171+ url = u ;
172+ done ( ) ;
173+ } )
174+ . req ( function ( req ) {
175+ req . session = { } ;
176+ } )
177+ . authenticate ( { openIDRealm : 'http://www.example.com/' } ) ;
178+ } ) ;
179+
180+ it ( 'should be redirected' , function ( ) {
181+ expect ( url ) . to . equal ( 'https://accounts.google.com/o/oauth2/v2/auth?openid.realm=http%3A%2F%2Fwww.example.com%2F&response_type=code&redirect_uri=&client_id=ABC123' ) ;
182+ } ) ;
183+ } ) ; // authorization request with OpenID 2.0 migration parameters
184+
185+ describe ( 'authorization request with undocumented parameters' , function ( ) {
186+ var strategy = new GoogleStrategy ( {
187+ clientID : 'ABC123' ,
188+ clientSecret : 'secret'
189+ } , function ( ) { } ) ;
190+
191+
192+ var url ;
193+
194+ before ( function ( done ) {
195+ chai . passport . use ( strategy )
196+ . redirect ( function ( u ) {
197+ url = u ;
198+ done ( ) ;
199+ } )
200+ . req ( function ( req ) {
201+ req . session = { } ;
202+ } )
203+ . authenticate ( { approvalPrompt : 'none' , userID : '1' } ) ;
204+ } ) ;
205+
206+ it ( 'should be redirected' , function ( ) {
207+ expect ( url ) . to . equal ( 'https://accounts.google.com/o/oauth2/v2/auth?approval_prompt=none&user_id=1&response_type=code&redirect_uri=&client_id=ABC123' ) ;
208+ } ) ;
209+ } ) ; // authorization request with undocumented parameters
210+
21211} ) ;
0 commit comments