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<
|
export async function getGoogleDatasourceConfig(): Promise<
|
||||||
GoogleInnerConfig | undefined
|
GoogleInnerConfig | undefined
|
||||||
> {
|
> {
|
||||||
if (!env.isDev() && !env.SELF_HOSTED) {
|
if (!env.SELF_HOSTED) {
|
||||||
// always use the env vars in cloud
|
// always use the env vars in cloud
|
||||||
return getDefaultGoogleConfig()
|
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 { ConfigType } from "@budibase/types"
|
||||||
import env from "../../environment"
|
import env from "../../environment"
|
||||||
import * as configs from "../configs"
|
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 {
|
import {
|
||||||
|
ConfigType,
|
||||||
|
GoogleConfig,
|
||||||
GoogleInnerConfig,
|
GoogleInnerConfig,
|
||||||
JwtClaims,
|
JwtClaims,
|
||||||
OAuth2,
|
OAuth2,
|
||||||
|
@ -10,10 +12,10 @@ import {
|
||||||
User,
|
User,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator } from "./generator"
|
import { generator } from "./generator"
|
||||||
import { uuid, email } from "./common"
|
import { email, uuid } from "./common"
|
||||||
import * as shared from "./shared"
|
import * as shared from "./shared"
|
||||||
import _ from "lodash"
|
|
||||||
import { user } from "./shared"
|
import { user } from "./shared"
|
||||||
|
import _ from "lodash"
|
||||||
|
|
||||||
export function OAuth(): OAuth2 {
|
export function OAuth(): OAuth2 {
|
||||||
return {
|
return {
|
||||||
|
@ -107,3 +109,11 @@ export function googleConfig(): GoogleInnerConfig {
|
||||||
clientSecret: generator.string(),
|
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
|
// kill the reference so the input isn't saved
|
||||||
let datasource = cloneDeep(integration)
|
let datasource = cloneDeep(integration)
|
||||||
$: isGoogleConfigured = !!$organisation.google
|
$: isGoogleConfigured = !!$organisation.googleDatasourceConfigured
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await organisation.init()
|
await organisation.init()
|
||||||
|
|
|
@ -19,6 +19,7 @@ const DEFAULT_CONFIG = {
|
||||||
company: "Budibase",
|
company: "Budibase",
|
||||||
oidc: undefined,
|
oidc: undefined,
|
||||||
google: undefined,
|
google: undefined,
|
||||||
|
googleDatasourceConfigured: undefined,
|
||||||
oidcCallbackUrl: "",
|
oidcCallbackUrl: "",
|
||||||
googleCallbackUrl: "",
|
googleCallbackUrl: "",
|
||||||
isSSOEnforced: false,
|
isSSOEnforced: false,
|
||||||
|
@ -39,6 +40,7 @@ export function createOrganisationStore() {
|
||||||
const storeConfig = _.cloneDeep(get(store))
|
const storeConfig = _.cloneDeep(get(store))
|
||||||
delete storeConfig.oidc
|
delete storeConfig.oidc
|
||||||
delete storeConfig.google
|
delete storeConfig.google
|
||||||
|
delete storeConfig.googleDatasourceConfigured
|
||||||
delete storeConfig.oidcCallbackUrl
|
delete storeConfig.oidcCallbackUrl
|
||||||
delete storeConfig.googleCallbackUrl
|
delete storeConfig.googleCallbackUrl
|
||||||
await API.saveConfig({
|
await API.saveConfig({
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { SettingsConfig, SettingsInnerConfig } from "../../../documents"
|
||||||
*/
|
*/
|
||||||
export interface PublicSettingsInnerConfig extends SettingsInnerConfig {
|
export interface PublicSettingsInnerConfig extends SettingsInnerConfig {
|
||||||
google: boolean
|
google: boolean
|
||||||
|
googleDatasourceConfigured: boolean
|
||||||
oidc: boolean
|
oidc: boolean
|
||||||
oidcCallbackUrl: string
|
oidcCallbackUrl: string
|
||||||
googleCallbackUrl: string
|
googleCallbackUrl: string
|
||||||
|
|
|
@ -332,6 +332,8 @@ export async function publicSettings(
|
||||||
|
|
||||||
// google
|
// google
|
||||||
const googleConfig = await configs.getGoogleConfig()
|
const googleConfig = await configs.getGoogleConfig()
|
||||||
|
const googleDatasourceConfigured =
|
||||||
|
!!(await configs.getGoogleDatasourceConfig())
|
||||||
const preActivated = googleConfig && googleConfig.activated == null
|
const preActivated = googleConfig && googleConfig.activated == null
|
||||||
const google = preActivated || !!googleConfig?.activated
|
const google = preActivated || !!googleConfig?.activated
|
||||||
const _googleCallbackUrl = await googleCallbackUrl(googleConfig)
|
const _googleCallbackUrl = await googleCallbackUrl(googleConfig)
|
||||||
|
@ -352,6 +354,7 @@ export async function publicSettings(
|
||||||
...config,
|
...config,
|
||||||
...branding,
|
...branding,
|
||||||
google,
|
google,
|
||||||
|
googleDatasourceConfigured,
|
||||||
oidc,
|
oidc,
|
||||||
isSSOEnforced,
|
isSSOEnforced,
|
||||||
oidcCallbackUrl: _oidcCallbackUrl,
|
oidcCallbackUrl: _oidcCallbackUrl,
|
||||||
|
|
|
@ -290,6 +290,7 @@ describe("configs", () => {
|
||||||
logoUrl: "",
|
logoUrl: "",
|
||||||
analyticsEnabled: false,
|
analyticsEnabled: false,
|
||||||
google: false,
|
google: false,
|
||||||
|
googleDatasourceConfigured: false,
|
||||||
googleCallbackUrl: `http://localhost:10000/api/global/auth/${config.tenantId}/google/callback`,
|
googleCallbackUrl: `http://localhost:10000/api/global/auth/${config.tenantId}/google/callback`,
|
||||||
isSSOEnforced: false,
|
isSSOEnforced: false,
|
||||||
oidc: false,
|
oidc: false,
|
||||||
|
|
Loading…
Reference in New Issue