@@ -306,6 +306,208 @@ describe('API Console request', () => {
306306 assert . exists ( authorizationMethod . shadowRoot . querySelector ( '.auth-button' ) ) ;
307307 } ) ;
308308 } )
309+
310+ describe ( 'Basic' , ( ) => {
311+ let credentialsSection
312+
313+ beforeEach ( async ( ) => {
314+ await navigationSelectEndpointMethod ( element , '/test-basic-scheme' , 'get' ) ;
315+ await aTimeout ( 50 )
316+ documentationTryItButton ( element ) . click ( )
317+ await aTimeout ( 50 )
318+ credentialsSection = requestCredentialsSection ( element ) ;
319+ } ) ;
320+
321+ it ( `should render credentials section` , async ( ) => {
322+ assert . exists ( credentialsSection ) ;
323+ } ) ;
324+
325+ it ( `should render auth label` , async ( ) => {
326+ await aTimeout ( 100 ) ;
327+ assert . equal ( credentialsSection . shadowRoot . querySelector ( '.auth-selector-label' ) . innerText , 'Basic Authentication' ) ;
328+ } ) ;
329+
330+ it ( `should render authorization method` , async ( ) => {
331+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
332+ assert . equal ( authorizationMethod . getAttribute ( 'type' ) , 'basic' ) ;
333+ } ) ;
334+
335+ it ( `should render scheme fields` , async ( ) => {
336+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
337+ const authorizationMethodForm = authorizationMethod . shadowRoot . querySelector ( 'form' ) ;
338+
339+ assertInput ( authorizationMethodForm , 'username' , 'User name' )
340+ assertMaskedInput ( authorizationMethodForm , 'password' , 'Password' )
341+ } ) ;
342+
343+ it ( `should render all sections` , async ( ) => {
344+ assert . exists ( requestUrlSection ( element ) ) ;
345+ assert . exists ( requestSendButton ( element ) ) ;
346+ } ) ;
347+
348+ describe ( 'Basic auth request' , ( ) => {
349+ beforeEach ( async ( ) => {
350+ spy = sinon . spy ( ) ;
351+ document . body . addEventListener ( 'api-request' , spy ) ;
352+ } ) ;
353+
354+ it ( `should add auth to request` , async ( ) => {
355+ requestSendButton ( element ) . click ( ) ;
356+ await nextFrame ( ) ;
357+
358+ assert . isTrue ( spy . called ) ;
359+
360+ const authElement = spy . getCall ( 0 ) . args [ 0 ] . detail . auth [ 0 ] ;
361+ assert . equal ( authElement . type , 'basic' ) ;
362+ assert . equal ( authElement . config . password , '' ) ;
363+ assert . equal ( authElement . config . username , '' ) ;
364+ } ) ;
365+ } ) ;
366+ } )
367+
368+ describe ( 'Digest' , ( ) => {
369+ let credentialsSection
370+
371+ beforeEach ( async ( ) => {
372+ await navigationSelectEndpointMethod ( element , '/test-digest-scheme' , 'get' ) ;
373+ await aTimeout ( 50 )
374+ documentationTryItButton ( element ) . click ( )
375+ await aTimeout ( 50 )
376+ credentialsSection = requestCredentialsSection ( element ) ;
377+ } ) ;
378+
379+ it ( `should render credentials section` , async ( ) => {
380+ assert . exists ( credentialsSection ) ;
381+ } ) ;
382+
383+ it ( `should render auth label` , async ( ) => {
384+ await aTimeout ( 100 ) ;
385+ assert . equal ( credentialsSection . shadowRoot . querySelector ( '.auth-selector-label' ) . innerText , 'Digest Authentication' ) ;
386+ } ) ;
387+
388+ it ( `should render authorization method` , async ( ) => {
389+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
390+ assert . equal ( authorizationMethod . getAttribute ( 'type' ) , 'digest' ) ;
391+ } ) ;
392+
393+ it ( `should render scheme fields` , async ( ) => {
394+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
395+ const authorizationMethodForm = authorizationMethod . shadowRoot . querySelector ( 'form' ) ;
396+
397+ assertInput ( authorizationMethodForm , 'username' , 'User name' )
398+ assertInput ( authorizationMethodForm , 'realm' , 'Server issued realm' )
399+ assertInput ( authorizationMethodForm , 'nonce' , 'Server issued nonce' )
400+ assertInput ( authorizationMethodForm , 'nc' , 'Nonce count' )
401+ assertInput ( authorizationMethodForm , 'opaque' , 'Server issued opaque string' )
402+ assertInput ( authorizationMethodForm , 'cnonce' , 'Client nonce' )
403+
404+ assertMaskedInput ( authorizationMethodForm , 'password' , 'Password' )
405+
406+ assertDropdownMenu ( authorizationMethodForm , 'qop' , 'Quality of protection' , 'Access token' )
407+ assertDropdownMenu ( authorizationMethodForm , 'algorithm' , 'Hash algorithm' , 'MD5' )
408+ } ) ;
409+
410+ it ( `should render all sections` , async ( ) => {
411+ assert . exists ( requestUrlSection ( element ) ) ;
412+ assert . exists ( requestSendButton ( element ) ) ;
413+ } ) ;
414+
415+ describe ( 'Digest auth request' , ( ) => {
416+ beforeEach ( async ( ) => {
417+ spy = sinon . spy ( ) ;
418+ document . body . addEventListener ( 'api-request' , spy ) ;
419+ } ) ;
420+
421+ it ( `should add auth to request` , async ( ) => {
422+ requestSendButton ( element ) . click ( ) ;
423+ await nextFrame ( ) ;
424+
425+ assert . isTrue ( spy . called ) ;
426+
427+ const authElement = spy . getCall ( 0 ) . args [ 0 ] . detail . auth [ 0 ] ;
428+ assert . equal ( authElement . type , 'digest' ) ;
429+ assert . equal ( authElement . config . username , '' ) ;
430+ assert . equal ( authElement . config . password , '' ) ;
431+ assert . equal ( authElement . config . response , 'b51d5ed92022b12518f81219d05e0ea1' ) ;
432+ assert . equal ( authElement . config . nc , '00000001' ) ;
433+ assert . isDefined ( authElement . config . cnonce ) ;
434+ assert . equal ( authElement . config . algorithm , 'MD5' ) ;
435+ assert . isUndefined ( authElement . config . realm ) ;
436+ assert . isUndefined ( authElement . config . nonce ) ;
437+ assert . isUndefined ( authElement . config . uri ) ;
438+ assert . isUndefined ( authElement . config . opaque ) ;
439+ assert . isUndefined ( authElement . config . qop ) ;
440+ } ) ;
441+ } ) ;
442+ } )
443+
444+ describe ( 'Pass through' , ( ) => {
445+ let credentialsSection
446+
447+ beforeEach ( async ( ) => {
448+ await navigationSelectEndpointMethod ( element , '/test-pass-through-scheme' , 'get' ) ;
449+ await aTimeout ( 50 )
450+ documentationTryItButton ( element ) . click ( )
451+ await aTimeout ( 50 )
452+ credentialsSection = requestCredentialsSection ( element ) ;
453+ } ) ;
454+
455+ it ( `should render credentials section` , async ( ) => {
456+ assert . exists ( credentialsSection ) ;
457+ } ) ;
458+
459+ it ( `should render auth label` , async ( ) => {
460+ await aTimeout ( 100 ) ;
461+ assert . equal ( credentialsSection . shadowRoot . querySelector ( '.auth-selector-label' ) . innerText , 'Pass Through' ) ;
462+ } ) ;
463+
464+ it ( `should render authorization method` , async ( ) => {
465+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
466+ assert . equal ( authorizationMethod . getAttribute ( 'type' ) , 'pass through' ) ;
467+ } ) ;
468+
469+ it ( `should render scheme fields` , async ( ) => {
470+ const authorizationMethod = credentialsSection . shadowRoot . querySelector ( 'api-authorization-method' ) ;
471+ assert . equal ( authorizationMethod . shadowRoot . querySelector ( '.subtitle' ) . innerText . trim ( ) , 'Scheme: passthrough' ) ;
472+ assert . exists ( authorizationMethod . shadowRoot . querySelector ( '.hint-icon' ) ) ;
473+
474+ const authorizationMethodForm = authorizationMethod . shadowRoot . querySelector ( 'form' ) ;
475+ const titles = authorizationMethodForm . querySelectorAll ( '.section-title' ) ;
476+ assert . lengthOf ( titles , 2 )
477+ assert . equal ( titles [ 0 ] . innerText , 'Headers' )
478+ assert . equal ( titles [ 1 ] . innerText , 'Query parameters' )
479+
480+ const items = authorizationMethodForm . querySelectorAll ( 'api-form-item' ) ;
481+ assert . lengthOf ( items , 2 )
482+ assert . equal ( items [ 0 ] . getAttribute ( 'name' ) , 'api_key' )
483+ assert . equal ( items [ 0 ] . getAttribute ( 'data-type' ) , 'header' )
484+ assert . equal ( items [ 1 ] . getAttribute ( 'name' ) , 'query' )
485+ assert . equal ( items [ 1 ] . getAttribute ( 'data-type' ) , 'query' )
486+ } ) ;
487+
488+ it ( `should render all sections` , async ( ) => {
489+ assert . exists ( requestUrlSection ( element ) ) ;
490+ assert . exists ( requestSendButton ( element ) ) ;
491+ } ) ;
492+
493+ describe ( 'Pass through auth request' , ( ) => {
494+ beforeEach ( async ( ) => {
495+ spy = sinon . spy ( ) ;
496+ document . body . addEventListener ( 'api-request' , spy ) ;
497+ } ) ;
498+
499+ it ( `should add auth to request` , async ( ) => {
500+ requestSendButton ( element ) . click ( ) ;
501+ await nextFrame ( ) ;
502+
503+ assert . isTrue ( spy . called ) ;
504+ const authElement = spy . getCall ( 0 ) . args [ 0 ] . detail . auth [ 0 ] ;
505+ assert . equal ( authElement . type , 'pass through' ) ;
506+ assert . equal ( authElement . config . headers . api_key , '' ) ;
507+ assert . isUndefined ( authElement . config . query ) ;
508+ } ) ;
509+ } ) ;
510+ } )
309511 } ) ;
310512 } ) ;
311513 } ) ;
0 commit comments