Explictly check for google datasource configured (#10165)
* Explictly check for google datasource configured * Unit tests for getGoogleDatasourceConfig * Update /api/global/configs/public test + lint
This commit is contained in:
parent
249699859c
commit
38e6d61709
|
@ -162,7 +162,7 @@ export async function getGoogleConfig(): Promise<
|
|||
export async function getGoogleDatasourceConfig(): Promise<
|
||||
GoogleInnerConfig | undefined
|
||||
> {
|
||||
if (!env.isDev() && !env.SELF_HOSTED) {
|
||||
if (!env.SELF_HOSTED) {
|
||||
// always use the env vars in cloud
|
||||
return getDefaultGoogleConfig()
|
||||
}
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
import { DBTestConfiguration, generator, testEnv } from "../../../tests"
|
||||
import {
|
||||
DBTestConfiguration,
|
||||
generator,
|
||||
testEnv,
|
||||
structures,
|
||||
} from "../../../tests"
|
||||
import { ConfigType } from "@budibase/types"
|
||||
import env from "../../environment"
|
||||
import * as configs from "../configs"
|
||||
|
@ -113,4 +118,71 @@ describe("configs", () => {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("getGoogleDatasourceConfig", () => {
|
||||
function setEnvVars() {
|
||||
env.GOOGLE_CLIENT_SECRET = "test"
|
||||
env.GOOGLE_CLIENT_ID = "test"
|
||||
}
|
||||
|
||||
function unsetEnvVars() {
|
||||
env.GOOGLE_CLIENT_SECRET = undefined
|
||||
env.GOOGLE_CLIENT_ID = undefined
|
||||
}
|
||||
|
||||
describe("cloud", () => {
|
||||
beforeEach(() => {
|
||||
testEnv.cloudHosted()
|
||||
})
|
||||
|
||||
it("returns from env vars", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
setEnvVars()
|
||||
const config = await configs.getGoogleDatasourceConfig()
|
||||
unsetEnvVars()
|
||||
|
||||
expect(config).toEqual({
|
||||
activated: true,
|
||||
clientID: "test",
|
||||
clientSecret: "test",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it("returns undefined when no env vars are configured", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
const config = await configs.getGoogleDatasourceConfig()
|
||||
expect(config).toBeUndefined()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("self host", () => {
|
||||
beforeEach(() => {
|
||||
testEnv.selfHosted()
|
||||
})
|
||||
|
||||
it("returns from config", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
const googleDoc = structures.sso.googleConfigDoc()
|
||||
await configs.save(googleDoc)
|
||||
const config = await configs.getGoogleDatasourceConfig()
|
||||
expect(config).toEqual(googleDoc.config)
|
||||
})
|
||||
})
|
||||
|
||||
it("falls back to env vars when config is disabled", async () => {
|
||||
await config.doInTenant(async () => {
|
||||
setEnvVars()
|
||||
const config = await configs.getGoogleDatasourceConfig()
|
||||
unsetEnvVars()
|
||||
expect(config).toEqual({
|
||||
activated: true,
|
||||
clientID: "test",
|
||||
clientSecret: "test",
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import {
|
||||
ConfigType,
|
||||
GoogleConfig,
|
||||
GoogleInnerConfig,
|
||||
JwtClaims,
|
||||
OAuth2,
|
||||
|
@ -10,10 +12,10 @@ import {
|
|||
User,
|
||||
} from "@budibase/types"
|
||||
import { generator } from "./generator"
|
||||
import { uuid, email } from "./common"
|
||||
import { email, uuid } from "./common"
|
||||
import * as shared from "./shared"
|
||||
import _ from "lodash"
|
||||
import { user } from "./shared"
|
||||
import _ from "lodash"
|
||||
|
||||
export function OAuth(): OAuth2 {
|
||||
return {
|
||||
|
@ -107,3 +109,11 @@ export function googleConfig(): GoogleInnerConfig {
|
|||
clientSecret: generator.string(),
|
||||
}
|
||||
}
|
||||
|
||||
export function googleConfigDoc(): GoogleConfig {
|
||||
return {
|
||||
_id: "config_google",
|
||||
type: ConfigType.GOOGLE,
|
||||
config: googleConfig(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
// kill the reference so the input isn't saved
|
||||
let datasource = cloneDeep(integration)
|
||||
$: isGoogleConfigured = !!$organisation.google
|
||||
$: isGoogleConfigured = !!$organisation.googleDatasourceConfigured
|
||||
|
||||
onMount(async () => {
|
||||
await organisation.init()
|
||||
|
|
|
@ -19,6 +19,7 @@ const DEFAULT_CONFIG = {
|
|||
company: "Budibase",
|
||||
oidc: undefined,
|
||||
google: undefined,
|
||||
googleDatasourceConfigured: undefined,
|
||||
oidcCallbackUrl: "",
|
||||
googleCallbackUrl: "",
|
||||
isSSOEnforced: false,
|
||||
|
@ -39,6 +40,7 @@ export function createOrganisationStore() {
|
|||
const storeConfig = _.cloneDeep(get(store))
|
||||
delete storeConfig.oidc
|
||||
delete storeConfig.google
|
||||
delete storeConfig.googleDatasourceConfigured
|
||||
delete storeConfig.oidcCallbackUrl
|
||||
delete storeConfig.googleCallbackUrl
|
||||
await API.saveConfig({
|
||||
|
|
|
@ -5,6 +5,7 @@ import { SettingsConfig, SettingsInnerConfig } from "../../../documents"
|
|||
*/
|
||||
export interface PublicSettingsInnerConfig extends SettingsInnerConfig {
|
||||
google: boolean
|
||||
googleDatasourceConfigured: boolean
|
||||
oidc: boolean
|
||||
oidcCallbackUrl: string
|
||||
googleCallbackUrl: string
|
||||
|
|
|
@ -332,6 +332,8 @@ export async function publicSettings(
|
|||
|
||||
// google
|
||||
const googleConfig = await configs.getGoogleConfig()
|
||||
const googleDatasourceConfigured =
|
||||
!!(await configs.getGoogleDatasourceConfig())
|
||||
const preActivated = googleConfig && googleConfig.activated == null
|
||||
const google = preActivated || !!googleConfig?.activated
|
||||
const _googleCallbackUrl = await googleCallbackUrl(googleConfig)
|
||||
|
@ -352,6 +354,7 @@ export async function publicSettings(
|
|||
...config,
|
||||
...branding,
|
||||
google,
|
||||
googleDatasourceConfigured,
|
||||
oidc,
|
||||
isSSOEnforced,
|
||||
oidcCallbackUrl: _oidcCallbackUrl,
|
||||
|
|
|
@ -290,6 +290,7 @@ describe("configs", () => {
|
|||
logoUrl: "",
|
||||
analyticsEnabled: false,
|
||||
google: false,
|
||||
googleDatasourceConfigured: false,
|
||||
googleCallbackUrl: `http://localhost:10000/api/global/auth/${config.tenantId}/google/callback`,
|
||||
isSSOEnforced: false,
|
||||
oidc: false,
|
||||
|
|
Loading…
Reference in New Issue