wrap-auth-selectors.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import { fromJS, Map } from "immutable"
  2. import {
  3. definitionsToAuthorize
  4. } from "corePlugins/oas3/auth-extensions/wrap-selectors"
  5. describe("oas3 plugin - auth extensions - wrapSelectors", function(){
  6. describe("execute", function(){
  7. it("should add `securities` to the oriAction call", function(){
  8. // Given
  9. const system = {
  10. getSystem: () => system,
  11. getState: () => new Map(),
  12. specSelectors: {
  13. specJson: () => fromJS({
  14. openapi: "3.0.0"
  15. }),
  16. securityDefinitions: () => {
  17. return fromJS({
  18. "oauth2AuthorizationCode": {
  19. "type": "oauth2",
  20. "flows": {
  21. "authorizationCode": {
  22. "authorizationUrl": "http://google.com/",
  23. "tokenUrl": "http://google.com/",
  24. "scopes": {
  25. "myScope": "our only scope"
  26. }
  27. }
  28. }
  29. },
  30. "oauth2Multiflow": {
  31. "type": "oauth2",
  32. "flows": {
  33. "clientCredentials": {
  34. "tokenUrl": "http://google.com/",
  35. "scopes": {
  36. "myScope": "our only scope"
  37. }
  38. },
  39. "password": {
  40. "tokenUrl": "http://google.com/",
  41. "scopes": {
  42. "myScope": "our only scope"
  43. }
  44. },
  45. "authorizationCode": {
  46. "authorizationUrl": "http://google.com/",
  47. "tokenUrl": "http://google.com/",
  48. "scopes": {
  49. "myScope": "our only scope"
  50. }
  51. }
  52. }
  53. },
  54. "oidc": {
  55. "type": "openIdConnect",
  56. "openIdConnectUrl": "https://accounts.google.com/.well-known/openid-configuration",
  57. "openIdConnectData": {
  58. "authorization_endpoint": "https://accounts.google.com/o/oauth2/v2/auth",
  59. "token_endpoint": "https://oauth2.googleapis.com/token",
  60. "scopes_supported": [
  61. "openid",
  62. "email",
  63. "profile"
  64. ],
  65. "grant_types_supported": [
  66. "authorization_code",
  67. "refresh_token",
  68. "urn:ietf:params:oauth:grant-type:device_code",
  69. "urn:ietf:params:oauth:grant-type:jwt-bearer"
  70. ]
  71. }
  72. },
  73. "oidcNoGrant": {
  74. "type": "openIdConnect",
  75. "openIdConnectUrl": "https://accounts.google.com/.well-known/openid-configuration",
  76. "openIdConnectData": {
  77. "authorization_endpoint": "https://accounts.google.com/o/oauth2/v2/auth",
  78. "token_endpoint": "https://oauth2.googleapis.com/token",
  79. "scopes_supported": [
  80. "openid",
  81. "email",
  82. "profile"
  83. ]
  84. },
  85. },
  86. })
  87. }
  88. }
  89. }
  90. // When
  91. let res = definitionsToAuthorize(() => null, system)()
  92. // Then
  93. expect(res.toJS()).toEqual([
  94. {
  95. oauth2AuthorizationCode: {
  96. flow: "authorizationCode",
  97. authorizationUrl: "http://google.com/",
  98. tokenUrl: "http://google.com/",
  99. scopes: {
  100. "myScope": "our only scope"
  101. },
  102. type: "oauth2"
  103. }
  104. },
  105. {
  106. oauth2Multiflow: {
  107. flow: "clientCredentials",
  108. tokenUrl: "http://google.com/",
  109. scopes: {
  110. "myScope": "our only scope"
  111. },
  112. type: "oauth2"
  113. }
  114. },
  115. {
  116. oauth2Multiflow: {
  117. flow: "password",
  118. tokenUrl: "http://google.com/",
  119. scopes: {
  120. "myScope": "our only scope"
  121. },
  122. type: "oauth2"
  123. }
  124. },
  125. {
  126. oauth2Multiflow: {
  127. flow: "authorizationCode",
  128. authorizationUrl: "http://google.com/",
  129. tokenUrl: "http://google.com/",
  130. scopes: {
  131. "myScope": "our only scope"
  132. },
  133. type: "oauth2"
  134. }
  135. },
  136. {
  137. oidc: {
  138. flow: "authorization_code",
  139. authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
  140. tokenUrl: "https://oauth2.googleapis.com/token",
  141. openIdConnectUrl: "https://accounts.google.com/.well-known/openid-configuration",
  142. scopes: {
  143. "openid": "",
  144. "email": "",
  145. "profile": "",
  146. },
  147. type: "oauth2"
  148. }
  149. },
  150. {
  151. oidc: {
  152. flow: "refresh_token",
  153. authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
  154. tokenUrl: "https://oauth2.googleapis.com/token",
  155. openIdConnectUrl: "https://accounts.google.com/.well-known/openid-configuration",
  156. scopes: {
  157. "openid": "",
  158. "email": "",
  159. "profile": "",
  160. },
  161. type: "oauth2"
  162. }
  163. },
  164. {
  165. oidc: {
  166. flow: "urn:ietf:params:oauth:grant-type:device_code",
  167. authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
  168. tokenUrl: "https://oauth2.googleapis.com/token",
  169. openIdConnectUrl: "https://accounts.google.com/.well-known/openid-configuration",
  170. scopes: {
  171. "openid": "",
  172. "email": "",
  173. "profile": "",
  174. },
  175. type: "oauth2"
  176. }
  177. },
  178. {
  179. oidc: {
  180. flow: "urn:ietf:params:oauth:grant-type:jwt-bearer",
  181. authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
  182. tokenUrl: "https://oauth2.googleapis.com/token",
  183. openIdConnectUrl: "https://accounts.google.com/.well-known/openid-configuration",
  184. scopes: {
  185. "openid": "",
  186. "email": "",
  187. "profile": "",
  188. },
  189. type: "oauth2"
  190. }
  191. },
  192. {
  193. // See https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
  194. // grant_types_supported
  195. // OPTIONAL. JSON array containing a list of the OAuth 2.0 Grant Type values that
  196. // this OP supports. Dynamic OpenID Providers MUST support the authorization_code
  197. // and implicit Grant Type values and MAY support other Grant Types. If omitted,
  198. // the default value is ["authorization_code", "implicit"].
  199. oidcNoGrant: {
  200. flow: "authorization_code",
  201. authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
  202. tokenUrl: "https://oauth2.googleapis.com/token",
  203. openIdConnectUrl: "https://accounts.google.com/.well-known/openid-configuration",
  204. scopes: {
  205. "openid": "",
  206. "email": "",
  207. "profile": "",
  208. },
  209. type: "oauth2"
  210. }
  211. },
  212. {
  213. oidcNoGrant: {
  214. flow: "implicit",
  215. authorizationUrl: "https://accounts.google.com/o/oauth2/v2/auth",
  216. tokenUrl: "https://oauth2.googleapis.com/token",
  217. openIdConnectUrl: "https://accounts.google.com/.well-known/openid-configuration",
  218. scopes: {
  219. "openid": "",
  220. "email": "",
  221. "profile": "",
  222. },
  223. type: "oauth2"
  224. }
  225. },
  226. ])
  227. })
  228. })
  229. })