oauth.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const oauthBlockBuilder = require("../../../docker/configurator/oauth")
  2. const dedent = require("dedent")
  3. describe("docker: env translator - oauth block", function() {
  4. it("should omit the block if there are no valid keys", function () {
  5. const input = {}
  6. expect(oauthBlockBuilder(input)).toEqual(``)
  7. })
  8. it("should omit the block if there are no valid keys", function () {
  9. const input = {
  10. NOT_A_VALID_KEY: "asdf1234"
  11. }
  12. expect(oauthBlockBuilder(input)).toEqual(``)
  13. })
  14. it("should generate a block from empty values", function() {
  15. const input = {
  16. OAUTH_CLIENT_ID: ``,
  17. OAUTH_CLIENT_SECRET: ``,
  18. OAUTH_REALM: ``,
  19. OAUTH_APP_NAME: ``,
  20. OAUTH_SCOPE_SEPARATOR: "",
  21. OAUTH_ADDITIONAL_PARAMS: ``,
  22. OAUTH_USE_PKCE: false
  23. }
  24. expect(oauthBlockBuilder(input)).toEqual(dedent(`
  25. ui.initOAuth({
  26. clientId: "",
  27. clientSecret: "",
  28. realm: "",
  29. appName: "",
  30. scopeSeparator: "",
  31. additionalQueryStringParams: undefined,
  32. usePkceWithAuthorizationCodeGrant: false,
  33. })`))
  34. })
  35. it("should generate a full block", function() {
  36. const input = {
  37. OAUTH_CLIENT_ID: `myId`,
  38. OAUTH_CLIENT_SECRET: `mySecret`,
  39. OAUTH_REALM: `myRealm`,
  40. OAUTH_APP_NAME: `myAppName`,
  41. OAUTH_SCOPE_SEPARATOR: "%21",
  42. OAUTH_ADDITIONAL_PARAMS: `{ "a": 1234, "b": "stuff" }`,
  43. OAUTH_USE_PKCE: true
  44. }
  45. expect(oauthBlockBuilder(input)).toEqual(dedent(`
  46. ui.initOAuth({
  47. clientId: "myId",
  48. clientSecret: "mySecret",
  49. realm: "myRealm",
  50. appName: "myAppName",
  51. scopeSeparator: "%21",
  52. additionalQueryStringParams: { "a": 1234, "b": "stuff" },
  53. usePkceWithAuthorizationCodeGrant: true,
  54. })`))
  55. })
  56. })