Fix tests

This commit is contained in:
Adria Navarro 2025-03-19 16:32:53 +01:00
parent 18a431df12
commit cc042e2093
2 changed files with 70 additions and 54 deletions

View File

@ -1,5 +1,6 @@
import { import {
OAuth2Config, OAuth2Config,
OAuth2CredentialsMethod,
PASSWORD_REPLACEMENT, PASSWORD_REPLACEMENT,
UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigRequest,
VirtualDocumentType, VirtualDocumentType,
@ -17,6 +18,7 @@ describe("/oauth2", () => {
url: generator.url(), url: generator.url(),
clientId: generator.guid(), clientId: generator.guid(),
clientSecret: generator.hash(), clientSecret: generator.hash(),
method: generator.pickone(Object.values(OAuth2CredentialsMethod)),
} }
} }
@ -54,6 +56,7 @@ describe("/oauth2", () => {
url: c.url, url: c.url,
clientId: c.clientId, clientId: c.clientId,
clientSecret: PASSWORD_REPLACEMENT, clientSecret: PASSWORD_REPLACEMENT,
method: c.method,
})) }))
), ),
}) })
@ -74,6 +77,7 @@ describe("/oauth2", () => {
url: oauth2Config.url, url: oauth2Config.url,
clientId: oauth2Config.clientId, clientId: oauth2Config.clientId,
clientSecret: PASSWORD_REPLACEMENT, clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config.method,
}, },
], ],
}) })
@ -93,6 +97,7 @@ describe("/oauth2", () => {
url: oauth2Config.url, url: oauth2Config.url,
clientId: oauth2Config.clientId, clientId: oauth2Config.clientId,
clientSecret: PASSWORD_REPLACEMENT, clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config.method,
}, },
{ {
id: expectOAuth2ConfigId, id: expectOAuth2ConfigId,
@ -100,6 +105,7 @@ describe("/oauth2", () => {
url: oauth2Config2.url, url: oauth2Config2.url,
clientId: oauth2Config2.clientId, clientId: oauth2Config2.clientId,
clientSecret: PASSWORD_REPLACEMENT, clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config2.method,
}, },
]) ])
expect(response.configs[0].id).not.toEqual(response.configs[1].id) expect(response.configs[0].id).not.toEqual(response.configs[1].id)
@ -125,6 +131,7 @@ describe("/oauth2", () => {
url: oauth2Config.url, url: oauth2Config.url,
clientId: oauth2Config.clientId, clientId: oauth2Config.clientId,
clientSecret: PASSWORD_REPLACEMENT, clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config.method,
}, },
]) ])
}) })
@ -161,6 +168,7 @@ describe("/oauth2", () => {
url: configData.url, url: configData.url,
clientId: configData.clientId, clientId: configData.clientId,
clientSecret: PASSWORD_REPLACEMENT, clientSecret: PASSWORD_REPLACEMENT,
method: configData.method,
}, },
]) ])
) )

View File

@ -6,6 +6,7 @@ import { generateToken } from "../utils"
import path from "path" import path from "path"
import { KEYCLOAK_IMAGE } from "../../../../integrations/tests/utils/images" import { KEYCLOAK_IMAGE } from "../../../../integrations/tests/utils/images"
import { startContainer } from "../../../../integrations/tests/utils" import { startContainer } from "../../../../integrations/tests/utils"
import { OAuth2CredentialsMethod } from "@budibase/types"
const config = new TestConfiguration() const config = new TestConfiguration()
@ -41,7 +42,9 @@ describe("oauth2 utils", () => {
keycloakUrl = `http://127.0.0.1:${port}` keycloakUrl = `http://127.0.0.1:${port}`
}) })
describe("generateToken", () => { describe.each(Object.values(OAuth2CredentialsMethod))(
"generateToken (in %s)",
method => {
it("successfully generates tokens", async () => { it("successfully generates tokens", async () => {
const response = await config.doInContext(config.appId, async () => { const response = await config.doInContext(config.appId, async () => {
const oauthConfig = await sdk.oauth2.create({ const oauthConfig = await sdk.oauth2.create({
@ -49,6 +52,7 @@ describe("oauth2 utils", () => {
url: `${keycloakUrl}/realms/myrealm/protocol/openid-connect/token`, url: `${keycloakUrl}/realms/myrealm/protocol/openid-connect/token`,
clientId: "my-client", clientId: "my-client",
clientSecret: "my-secret", clientSecret: "my-secret",
method,
}) })
const response = await generateToken(oauthConfig.id) const response = await generateToken(oauthConfig.id)
@ -66,6 +70,7 @@ describe("oauth2 utils", () => {
url: `${keycloakUrl}/realms/wrong/protocol/openid-connect/token`, url: `${keycloakUrl}/realms/wrong/protocol/openid-connect/token`,
clientId: "my-client", clientId: "my-client",
clientSecret: "my-secret", clientSecret: "my-secret",
method,
}) })
await generateToken(oauthConfig.id) await generateToken(oauthConfig.id)
@ -81,6 +86,7 @@ describe("oauth2 utils", () => {
url: `${keycloakUrl}/realms/myrealm/protocol/openid-connect/token`, url: `${keycloakUrl}/realms/myrealm/protocol/openid-connect/token`,
clientId: "wrong-client-id", clientId: "wrong-client-id",
clientSecret: "my-secret", clientSecret: "my-secret",
method,
}) })
await generateToken(oauthConfig.id) await generateToken(oauthConfig.id)
@ -98,6 +104,7 @@ describe("oauth2 utils", () => {
url: `${keycloakUrl}/realms/myrealm/protocol/openid-connect/token`, url: `${keycloakUrl}/realms/myrealm/protocol/openid-connect/token`,
clientId: "my-client", clientId: "my-client",
clientSecret: "wrong-secret", clientSecret: "wrong-secret",
method,
}) })
await generateToken(oauthConfig.id) await generateToken(oauthConfig.id)
@ -106,5 +113,6 @@ describe("oauth2 utils", () => {
"Error fetching oauth2 token: Invalid client or Invalid client credentials" "Error fetching oauth2 token: Invalid client or Invalid client credentials"
) )
}) })
}) }
)
}) })