sso activated/deactivated events + tests
This commit is contained in:
parent
fde16cf548
commit
9ebdf837fc
|
@ -13,7 +13,6 @@ exports.logout = () => {
|
||||||
events.processEvent(Events.AUTH_LOGOUT, properties)
|
events.processEvent(Events.AUTH_LOGOUT, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.SSOCreated = type => {
|
exports.SSOCreated = type => {
|
||||||
const properties = {
|
const properties = {
|
||||||
type,
|
type,
|
||||||
|
@ -21,7 +20,6 @@ exports.SSOCreated = type => {
|
||||||
events.processEvent(Events.AUTH_SSO_CREATED, properties)
|
events.processEvent(Events.AUTH_SSO_CREATED, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.SSOUpdated = type => {
|
exports.SSOUpdated = type => {
|
||||||
const properties = {
|
const properties = {
|
||||||
type,
|
type,
|
||||||
|
@ -29,7 +27,6 @@ exports.SSOUpdated = type => {
|
||||||
events.processEvent(Events.AUTH_SSO_UPDATED, properties)
|
events.processEvent(Events.AUTH_SSO_UPDATED, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.SSOActivated = type => {
|
exports.SSOActivated = type => {
|
||||||
const properties = {
|
const properties = {
|
||||||
type,
|
type,
|
||||||
|
@ -37,7 +34,6 @@ exports.SSOActivated = type => {
|
||||||
events.processEvent(Events.AUTH_SSO_ACTIVATED, properties)
|
events.processEvent(Events.AUTH_SSO_ACTIVATED, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
exports.SSODeactivated = type => {
|
exports.SSODeactivated = type => {
|
||||||
const properties = {
|
const properties = {
|
||||||
type,
|
type,
|
||||||
|
|
|
@ -34,9 +34,15 @@ const getEventFns = async (db, config) => {
|
||||||
break
|
break
|
||||||
case Configs.GOOGLE:
|
case Configs.GOOGLE:
|
||||||
fns.push(() => events.auth.SSOCreated(type))
|
fns.push(() => events.auth.SSOCreated(type))
|
||||||
|
if (config.config.activated) {
|
||||||
|
fns.push(() => events.auth.SSOActivated(type))
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case Configs.OIDC:
|
case Configs.OIDC:
|
||||||
fns.push(() => events.auth.SSOCreated(type))
|
fns.push(() => events.auth.SSOCreated(type))
|
||||||
|
if (config.config.configs[0].activated) {
|
||||||
|
fns.push(() => events.auth.SSOActivated(type))
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case Configs.SETTINGS:
|
case Configs.SETTINGS:
|
||||||
if (config.company) {
|
if (config.company) {
|
||||||
|
@ -57,9 +63,25 @@ const getEventFns = async (db, config) => {
|
||||||
break
|
break
|
||||||
case Configs.GOOGLE:
|
case Configs.GOOGLE:
|
||||||
fns.push(() => events.auth.SSOUpdated(type))
|
fns.push(() => events.auth.SSOUpdated(type))
|
||||||
|
if (!existing.config.activated && config.config.activated) {
|
||||||
|
fns.push(() => events.auth.SSOActivated(type))
|
||||||
|
} else if (existing.config.activated && !config.config.activated) {
|
||||||
|
fns.push(() => events.auth.SSODeactivated(type))
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case Configs.OIDC:
|
case Configs.OIDC:
|
||||||
fns.push(() => events.auth.SSOUpdated(type))
|
fns.push(() => events.auth.SSOUpdated(type))
|
||||||
|
if (
|
||||||
|
!existing.config.configs[0].activated &&
|
||||||
|
config.config.configs[0].activated
|
||||||
|
) {
|
||||||
|
fns.push(() => events.auth.SSOActivated(type))
|
||||||
|
} else if (
|
||||||
|
existing.config.configs[0].activated &&
|
||||||
|
!config.config.configs[0].activated
|
||||||
|
) {
|
||||||
|
fns.push(() => events.auth.SSODeactivated(type))
|
||||||
|
}
|
||||||
break
|
break
|
||||||
case Configs.SETTINGS:
|
case Configs.SETTINGS:
|
||||||
if (config.company && existing.company !== config.company) {
|
if (config.company && existing.company !== config.company) {
|
||||||
|
|
|
@ -17,16 +17,20 @@ describe("configs", () => {
|
||||||
jest.clearAllMocks()
|
jest.clearAllMocks()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(async () => {
|
||||||
|
await setup.afterAll()
|
||||||
|
})
|
||||||
|
|
||||||
describe("post /api/global/configs", () => {
|
describe("post /api/global/configs", () => {
|
||||||
|
|
||||||
const saveConfig = async (type, _id, _rev) => {
|
const saveConfig = async (conf, type, _id, _rev) => {
|
||||||
const data = {
|
const data = {
|
||||||
type,
|
type,
|
||||||
|
config: conf,
|
||||||
_id,
|
_id,
|
||||||
_rev
|
_rev
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await request
|
const res = await request
|
||||||
.post(`/api/global/configs`)
|
.post(`/api/global/configs`)
|
||||||
.send(data)
|
.send(data)
|
||||||
|
@ -34,50 +38,137 @@ describe("configs", () => {
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
.expect(200)
|
.expect(200)
|
||||||
|
|
||||||
return res.body
|
return {
|
||||||
|
...data,
|
||||||
|
...res.body
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("google", () => {
|
describe("google", () => {
|
||||||
const saveGoogleConfig = async (_id, _rev) => {
|
const saveGoogleConfig = async (conf, _id, _rev) => {
|
||||||
return saveConfig(Configs.GOOGLE, _id, _rev)
|
const googleConfig = {
|
||||||
|
clientID: "clientID",
|
||||||
|
clientSecret: "clientSecret",
|
||||||
|
activated: true,
|
||||||
|
...conf
|
||||||
}
|
}
|
||||||
|
|
||||||
it ("should create google config", async () => {
|
return saveConfig(googleConfig, Configs.GOOGLE, _id, _rev)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("create", () => {
|
||||||
|
it ("should create activated google config", async () => {
|
||||||
await saveGoogleConfig()
|
await saveGoogleConfig()
|
||||||
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
||||||
expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
|
||||||
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledWith(Configs.GOOGLE)
|
||||||
await config.deleteConfig(Configs.GOOGLE)
|
await config.deleteConfig(Configs.GOOGLE)
|
||||||
})
|
})
|
||||||
|
|
||||||
it ("should update google config", async () => {
|
it ("should create deactivated google config", async () => {
|
||||||
|
await saveGoogleConfig({ activated: false })
|
||||||
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.GOOGLE)
|
||||||
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
||||||
|
await config.deleteConfig(Configs.GOOGLE)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("update", () => {
|
||||||
|
it ("should update google config to deactivated", async () => {
|
||||||
const googleConf = await saveGoogleConfig()
|
const googleConf = await saveGoogleConfig()
|
||||||
await saveGoogleConfig(googleConf._id, googleConf._rev)
|
jest.clearAllMocks()
|
||||||
|
await saveGoogleConfig({ ...googleConf.config, activated: false }, googleConf._id, googleConf._rev)
|
||||||
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
||||||
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
|
||||||
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSODeactivated).toBeCalledWith(Configs.GOOGLE)
|
||||||
await config.deleteConfig(Configs.GOOGLE)
|
await config.deleteConfig(Configs.GOOGLE)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it ("should update google config to activated", async () => {
|
||||||
|
const googleConf = await saveGoogleConfig({ activated: false })
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await saveGoogleConfig({ ...googleConf.config, activated: true}, googleConf._id, googleConf._rev)
|
||||||
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.GOOGLE)
|
||||||
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledWith(Configs.GOOGLE)
|
||||||
|
await config.deleteConfig(Configs.GOOGLE)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("oidc", () => {
|
describe("oidc", () => {
|
||||||
const saveOIDCConfig = async (_id, _rev) => {
|
const saveOIDCConfig = async (conf, _id, _rev) => {
|
||||||
return saveConfig(Configs.OIDC, _id, _rev)
|
const oidcConfig = {
|
||||||
|
configs: [{
|
||||||
|
clientID: "clientID",
|
||||||
|
clientSecret: "clientSecret",
|
||||||
|
configUrl: "http://example.com",
|
||||||
|
logo: "logo",
|
||||||
|
name: "oidc",
|
||||||
|
uuid: "uuid",
|
||||||
|
activated: true,
|
||||||
|
...conf
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
return saveConfig(oidcConfig, Configs.OIDC, _id, _rev)
|
||||||
}
|
}
|
||||||
|
|
||||||
it ("should create OIDC config", async () => {
|
describe("create", () => {
|
||||||
|
it ("should create activated OIDC config", async () => {
|
||||||
await saveOIDCConfig()
|
await saveOIDCConfig()
|
||||||
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
||||||
expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
|
||||||
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledWith(Configs.OIDC)
|
||||||
await config.deleteConfig(Configs.OIDC)
|
await config.deleteConfig(Configs.OIDC)
|
||||||
})
|
})
|
||||||
|
|
||||||
it ("should update OIDC config", async () => {
|
it ("should create deactivated OIDC config", async () => {
|
||||||
const oidcConf = await saveOIDCConfig()
|
await saveOIDCConfig({ activated: false })
|
||||||
await saveOIDCConfig(oidcConf._id, oidcConf._rev)
|
expect(events.auth.SSOCreated).toBeCalledTimes(1)
|
||||||
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
expect(events.auth.SSOCreated).toBeCalledWith(Configs.OIDC)
|
||||||
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
||||||
await config.deleteConfig(Configs.OIDC)
|
await config.deleteConfig(Configs.OIDC)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("update", () => {
|
||||||
|
it ("should update OIDC config to deactivated", async () => {
|
||||||
|
const oidcConf = await saveOIDCConfig()
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await saveOIDCConfig({ ...oidcConf.config.configs[0], activated: false }, oidcConf._id, oidcConf._rev)
|
||||||
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
|
||||||
|
expect(events.auth.SSOActivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSODeactivated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSODeactivated).toBeCalledWith(Configs.OIDC)
|
||||||
|
await config.deleteConfig(Configs.OIDC)
|
||||||
|
})
|
||||||
|
|
||||||
|
it ("should update google config to activated", async () => {
|
||||||
|
const oidcConf = await saveOIDCConfig({ activated: false })
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await saveOIDCConfig({ ...oidcConf.config.configs[0], activated: true}, oidcConf._id, oidcConf._rev)
|
||||||
|
expect(events.auth.SSOUpdated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOUpdated).toBeCalledWith(Configs.OIDC)
|
||||||
|
expect(events.auth.SSODeactivated).not.toBeCalled()
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledTimes(1)
|
||||||
|
expect(events.auth.SSOActivated).toBeCalledWith(Configs.OIDC)
|
||||||
|
await config.deleteConfig(Configs.OIDC)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
it("should return the correct checklist status based on the state of the budibase installation", async () => {
|
||||||
|
|
Loading…
Reference in New Issue