@@ -10,7 +10,9 @@ describe('Security Requirement Object', () => {
1010 beforeEach ( ( ) => {
1111 context = new Context ( namespace ) ;
1212 context . registerScheme ( 'customApiKey' ) ;
13- context . registerScheme ( 'customOauth2' ) ;
13+ context . registerScheme ( 'customOauth' ) ;
14+ context . oauthFlow ( 'oauthWithFlow' , 'oauthWithFlow implicit' ) ;
15+ context . oauthFlow ( 'oauthWithFlow' , 'oauthWithFlow authorization code' ) ;
1416 } ) ;
1517
1618 it ( 'provides warning when security requirement is not an object' , ( ) => {
@@ -52,7 +54,7 @@ describe('Security Requirement Object', () => {
5254
5355 it ( 'parses correctly a single scheme reference with scopes' , ( ) => {
5456 const securityRequirement = new namespace . elements . Object ( {
55- customOauth2 : [
57+ customOauth : [
5658 'scope1' ,
5759 'scope2' ,
5860 ] ,
@@ -66,7 +68,7 @@ describe('Security Requirement Object', () => {
6668 const arr = parseResult . get ( 0 ) ;
6769
6870 expect ( arr . length ) . to . equal ( 1 ) ;
69- expect ( arr . get ( 0 ) . element ) . to . equal ( 'customOauth2 ' ) ;
71+ expect ( arr . get ( 0 ) . element ) . to . equal ( 'customOauth ' ) ;
7072 expect ( arr . get ( 0 ) . length ) . to . equal ( 1 ) ;
7173
7274 const scopes = arr . get ( 0 ) . get ( 0 ) . value ;
@@ -79,7 +81,7 @@ describe('Security Requirement Object', () => {
7981
8082 it ( 'provides warning when scope is not a string' , ( ) => {
8183 const securityRequirement = new namespace . elements . Object ( {
82- customOauth2 : [
84+ customOauth : [
8385 'scope1' ,
8486 2 ,
8587 ] ,
@@ -93,7 +95,7 @@ describe('Security Requirement Object', () => {
9395 const arr = parseResult . get ( 0 ) ;
9496
9597 expect ( arr . length ) . to . equal ( 1 ) ;
96- expect ( arr . get ( 0 ) . element ) . to . equal ( 'customOauth2 ' ) ;
98+ expect ( arr . get ( 0 ) . element ) . to . equal ( 'customOauth ' ) ;
9799 expect ( arr . get ( 0 ) . length ) . to . equal ( 1 ) ;
98100
99101 const scopes = arr . get ( 0 ) . get ( 0 ) . value ;
@@ -102,13 +104,13 @@ describe('Security Requirement Object', () => {
102104 expect ( scopes . length ) . to . equal ( 1 ) ;
103105 expect ( scopes . get ( 0 ) . toValue ( ) ) . to . equal ( 'scope1' ) ;
104106
105- expect ( parseResult ) . to . contain . warning ( "'Security Requirement Object' 'customOauth2 ' array value is not a string" ) ;
107+ expect ( parseResult ) . to . contain . warning ( "'Security Requirement Object' 'customOauth ' array value is not a string" ) ;
106108 } ) ;
107109
108110 it ( 'parses correctly multi scheme references' , ( ) => {
109111 const securityRequirement = new namespace . elements . Object ( {
110112 customApiKey : [ ] ,
111- customOauth2 : [ ] ,
113+ customOauth : [ ] ,
112114 } ) ;
113115
114116 const parseResult = parse ( context , securityRequirement ) ;
@@ -121,7 +123,40 @@ describe('Security Requirement Object', () => {
121123 expect ( arr . length ) . to . equal ( 2 ) ;
122124 expect ( arr . get ( 0 ) . element ) . to . equal ( 'customApiKey' ) ;
123125 expect ( arr . get ( 0 ) . length ) . to . equal ( 0 ) ;
124- expect ( arr . get ( 1 ) . element ) . to . equal ( 'customOauth2 ' ) ;
126+ expect ( arr . get ( 1 ) . element ) . to . equal ( 'customOauth ' ) ;
125127 expect ( arr . get ( 1 ) . length ) . to . equal ( 0 ) ;
126128 } ) ;
129+
130+ it ( 'parses correctly oauth2 scheme with flows' , ( ) => {
131+ let scopes ;
132+ const securityRequirement = new namespace . elements . Object ( {
133+ oauthWithFlow : [
134+ 'scope' ,
135+ ] ,
136+ } ) ;
137+
138+ const parseResult = parse ( context , securityRequirement ) ;
139+
140+ expect ( parseResult . length ) . to . equal ( 1 ) ;
141+ expect ( parseResult . get ( 0 ) ) . to . be . instanceof ( namespace . elements . Array ) ;
142+
143+ const arr = parseResult . get ( 0 ) ;
144+
145+ expect ( arr . length ) . to . equal ( 2 ) ;
146+ expect ( arr . get ( 0 ) . element ) . to . equal ( 'oauthWithFlow implicit' ) ;
147+ expect ( arr . get ( 0 ) . length ) . to . equal ( 1 ) ;
148+
149+ scopes = arr . get ( 0 ) . get ( 0 ) . value ;
150+ expect ( scopes ) . to . be . instanceof ( namespace . elements . Array ) ;
151+ expect ( scopes . length ) . to . equal ( 1 ) ;
152+ expect ( scopes . get ( 0 ) . toValue ( ) ) . to . equal ( 'scope' ) ;
153+
154+ expect ( arr . get ( 1 ) . element ) . to . equal ( 'oauthWithFlow authorization code' ) ;
155+ expect ( arr . get ( 1 ) . length ) . to . equal ( 1 ) ;
156+
157+ scopes = arr . get ( 1 ) . get ( 0 ) . value ;
158+ expect ( scopes ) . to . be . instanceof ( namespace . elements . Array ) ;
159+ expect ( scopes . length ) . to . equal ( 1 ) ;
160+ expect ( scopes . get ( 0 ) . toValue ( ) ) . to . equal ( 'scope' ) ;
161+ } ) ;
127162} ) ;
0 commit comments