@@ -5,7 +5,7 @@ import '../api-console.js';
55import {
66 documentationTryItButton ,
77 navigationSelectEndpointMethod ,
8- requestBodySection ,
8+ requestBodySection , requestCredentialsSection ,
99 requestHeadersSection ,
1010 requestQueryParamSection , requestSendButton ,
1111 requestUrlSection
@@ -133,6 +133,175 @@ describe('API Console request', () => {
133133 assert . exists ( body . shadowRoot . querySelector ( 'raw-payload-editor' ) ) ;
134134 } ) ;
135135 } ) ;
136+
137+ describe ( 'Authorization' , ( ) => {
138+ const assertDropdownMenu = ( form , name , menuLabel , value ) => {
139+ const menu = form . querySelector ( `anypoint-dropdown-menu[name="${ name } "]` ) ;
140+ assert . exists ( menu ) ;
141+ assert . exists ( menu . shadowRoot . querySelector ( '.label' ) . innerText , menuLabel ) ;
142+ assert . exists ( menu . shadowRoot . querySelector ( '.input-wrapper' ) . innerText , value ) ;
143+ }
144+
145+ const assertMaskedInput = ( form , name , inputLabel ) => {
146+ const input = form . querySelector ( `anypoint-masked-input[name="${ name } "]` ) ;
147+ assert . exists ( input ) ;
148+ assert . exists ( input . querySelector ( 'label' ) . innerText , inputLabel ) ;
149+ }
150+
151+ const assertInput = ( form , name , inputLabel ) => {
152+ const input = form . querySelector ( `anypoint-input[name="${ name } "]` ) ;
153+ assert . exists ( input ) ;
154+ assert . exists ( input . querySelector ( 'label' ) . innerText , inputLabel ) ;
155+ }
156+
157+ describe ( 'x-other' , ( ) => {
158+ let credentialsSection
159+
160+ beforeEach ( async ( ) => {
161+ await navigationSelectEndpointMethod ( element , '/test-custom-scheme' , 'get' ) ;
162+ await aTimeout ( 50 )
163+ documentationTryItButton ( element ) . click ( )
164+ await aTimeout ( 50 )
165+ credentialsSection = requestCredentialsSection ( element ) ;
166+ } ) ;
167+
168+ it ( `should render credentials section` , async ( ) => {
169+ assert . exists ( credentialsSection ) ;
170+ } ) ;
171+
172+ it ( `should render auth label` , async ( ) => {
173+ assert . equal ( credentialsSection . shadowRoot . querySelector ( '.auth-selector-label' ) . innerText , 'x-custom' ) ;
174+ } ) ;
175+
176+ it ( `should render authorization method` , async ( ) => {
177+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
178+ assert . equal ( authorizationMethod . getAttribute ( 'type' ) , 'custom' ) ;
179+
180+ const authorizationMethodTitle = authorizationMethod . shadowRoot . querySelector ( '.subtitle' ) ;
181+ assert . equal ( authorizationMethodTitle . querySelector ( 'span' ) . innerText , 'Scheme: customScheme' ) ;
182+ assert . exists ( authorizationMethodTitle . querySelector ( '.hint-icon' ) ) ;
183+ } ) ;
184+
185+ it ( `should render scheme fields` , async ( ) => {
186+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
187+ const authorizationMethodForm = authorizationMethod . shadowRoot . querySelector ( 'form' ) ;
188+ assert . equal ( authorizationMethodForm . querySelector ( '.section-title' ) . innerText , 'Headers' ) ;
189+
190+ const fields = authorizationMethodForm . querySelectorAll ( '.field-value' ) ;
191+ assert . lengthOf ( fields , 1 ) ;
192+ const formItem = fields [ 0 ] . querySelector ( 'api-form-item' ) ;
193+ const input = formItem . shadowRoot . querySelector ( 'anypoint-input' ) ;
194+ assert . equal ( input . querySelector ( 'label' ) . innerText , 'SpecialToken*' ) ;
195+ assert . exists ( fields [ 0 ] . querySelector ( '.hint-icon' ) ) ;
196+ } ) ;
197+
198+ describe ( 'Request with credentials' , ( ) => {
199+ beforeEach ( async ( ) => {
200+ spy = sinon . spy ( ) ;
201+ document . body . addEventListener ( 'api-request' , spy ) ;
202+ } ) ;
203+
204+ it ( `should add all credential headers to request` , async ( ) => {
205+ requestSendButton ( element ) . click ( ) ;
206+ await nextFrame ( ) ;
207+
208+ assert . isTrue ( spy . called ) ;
209+ assert . equal ( spy . getCall ( 0 ) . args [ 0 ] . detail . headers , 'SpecialToken: special-token' ) ;
210+ } ) ;
211+ } ) ;
212+ } )
213+
214+ describe ( 'Oauth 1.0' , ( ) => {
215+ let credentialsSection
216+
217+ beforeEach ( async ( ) => {
218+ await navigationSelectEndpointMethod ( element , '/test-oauth10-scheme' , 'get' ) ;
219+ await aTimeout ( 50 )
220+ documentationTryItButton ( element ) . click ( )
221+ await aTimeout ( 50 )
222+ credentialsSection = requestCredentialsSection ( element ) ;
223+ } ) ;
224+
225+ it ( `should render credentials section` , async ( ) => {
226+ assert . exists ( credentialsSection ) ;
227+ } ) ;
228+
229+ it ( `should render auth label` , async ( ) => {
230+ assert . equal ( credentialsSection . shadowRoot . querySelector ( '.auth-selector-label' ) . innerText , 'OAuth 1.0' ) ;
231+ } ) ;
232+
233+ it ( `should render authorization method` , async ( ) => {
234+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
235+ assert . equal ( authorizationMethod . getAttribute ( 'type' ) , 'oauth 1' ) ;
236+ } ) ;
237+
238+ it ( `should render scheme fields` , async ( ) => {
239+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
240+ const authorizationMethodForm = authorizationMethod . shadowRoot . querySelector ( 'form' ) ;
241+
242+ assertDropdownMenu ( authorizationMethodForm , 'authTokenMethod' , 'Authorization token method' , 'POST' )
243+ assertDropdownMenu ( authorizationMethodForm , 'authParamsLocation' , 'Oauth parameters location' , 'Authorization header' )
244+ assertDropdownMenu ( authorizationMethodForm , 'signatureMethod' , 'Signature method' , 'HMAC-SHA1' )
245+
246+ assertMaskedInput ( authorizationMethodForm , 'consumerKey' , 'Consumer key' )
247+ assertMaskedInput ( authorizationMethodForm , 'consumerSecret' , 'Consumer secret' )
248+ assertMaskedInput ( authorizationMethodForm , 'token' , 'Token' )
249+ assertMaskedInput ( authorizationMethodForm , 'tokenSecret' , 'Token secret' )
250+ assertMaskedInput ( authorizationMethodForm , 'realm' , 'Realm' )
251+
252+ assertInput ( authorizationMethodForm , 'requestTokenUri' , 'Request token URI' )
253+ assertInput ( authorizationMethodForm , 'accessTokenUri' , 'Token Authorization URI' )
254+ assertInput ( authorizationMethodForm , 'authorizationUri' , 'User authorization dialog URI' )
255+ assertInput ( authorizationMethodForm , 'redirectUri' , 'Redirect URI' )
256+ assertInput ( authorizationMethodForm , 'timestamp' , 'Timestamp' )
257+ assertInput ( authorizationMethodForm , 'nonce' , 'Nonce' )
258+
259+ assert . exists ( authorizationMethod . shadowRoot . querySelector ( '.auth-button' ) ) ;
260+ } ) ;
261+ } )
262+
263+ describe ( 'Oauth 2.0' , ( ) => {
264+ let credentialsSection
265+
266+ beforeEach ( async ( ) => {
267+ await navigationSelectEndpointMethod ( element , '/test-oauth20-scheme' , 'get' ) ;
268+ await aTimeout ( 50 )
269+ documentationTryItButton ( element ) . click ( )
270+ await aTimeout ( 50 )
271+ credentialsSection = requestCredentialsSection ( element ) ;
272+ } ) ;
273+
274+ it ( `should render credentials section` , async ( ) => {
275+ assert . exists ( credentialsSection ) ;
276+ } ) ;
277+
278+ it ( `should render auth label` , async ( ) => {
279+ assert . equal ( credentialsSection . shadowRoot . querySelector ( '.auth-selector-label' ) . innerText , 'OAuth 2.0' ) ;
280+ } ) ;
281+
282+ it ( `should render authorization method` , async ( ) => {
283+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
284+ assert . equal ( authorizationMethod . getAttribute ( 'type' ) , 'oauth 2' ) ;
285+ } ) ;
286+
287+ it ( `should render scheme fields` , async ( ) => {
288+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
289+ const authorizationMethodForm = authorizationMethod . shadowRoot . querySelector ( 'form' ) ;
290+
291+ assertDropdownMenu ( authorizationMethodForm , 'grantType' , 'Response type' , 'Access token' )
292+ assertMaskedInput ( authorizationMethodForm , 'clientId' , 'Client id' )
293+ assertInput ( authorizationMethodForm , 'authorizationUri' , 'Authorization URI' )
294+
295+ const scopes = authorizationMethod . shadowRoot . querySelector ( 'oauth2-scope-selector' ) ;
296+ assert . exists ( scopes ) ;
297+ assert . equal ( scopes . shadowRoot . querySelector ( '.form-label' ) . innerText , 'Scopes' ) ;
298+ assert . exists ( scopes . shadowRoot . querySelector ( '.scope-input' ) ) ;
299+
300+ assert . exists ( authorizationMethod . shadowRoot . querySelector ( '.redirect-section span' ) . innerText , 'https://auth.advancedrestclient.com/oauth-popup.html' ) ;
301+ assert . exists ( authorizationMethod . shadowRoot . querySelector ( '.auth-button' ) ) ;
302+ } ) ;
303+ } )
304+ } ) ;
136305 } ) ;
137306 } ) ;
138307} ) ;
0 commit comments