Skip to content

Commit

Permalink
SALTO-5692: Okta: Upgrade Brand deploy definitions to new infra (#6092
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Nurdok committed Jun 27, 2024
1 parent a4f1f63 commit ec919e5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 30 deletions.
22 changes: 0 additions & 22 deletions packages/okta-adapter/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,28 +479,6 @@ const DEFAULT_TYPE_CUSTOMIZATIONS: OktaSwaggerApiConfig['types'] = {
},
},
},
Brand: {
deployRequests: {
add: {
url: '/api/v1/brands',
method: 'post',
},
modify: {
url: '/api/v1/brands/{brandId}',
method: 'put',
urlParamsToFields: {
brandId: 'id',
},
},
remove: {
url: '/api/v1/brands/{brandId}',
method: 'delete',
urlParamsToFields: {
brandId: 'id',
},
},
},
},
BrandTheme: {
deployRequests: {
add: {
Expand Down
3 changes: 2 additions & 1 deletion packages/okta-adapter/src/definitions/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import _ from 'lodash'
import { definitions, deployment } from '@salto-io/adapter-components'
import { getChangeData, isModificationChange } from '@salto-io/adapter-api'
import { AdditionalAction, ClientOptions } from './types'
import { GROUP_TYPE_NAME } from '../constants'
import { BRAND_TYPE_NAME, GROUP_TYPE_NAME } from '../constants'

type InstanceDeployApiDefinitions = definitions.deploy.InstanceDeployApiDefinitions<AdditionalAction, ClientOptions>
export type DeployApiDefinitions = definitions.deploy.DeployApiDefinitions<AdditionalAction, ClientOptions>
Expand All @@ -29,6 +29,7 @@ const createCustomizations = (): Record<string, InstanceDeployApiDefinitions> =>
ClientOptions
>({
[GROUP_TYPE_NAME]: { bulkPath: '/api/v1/groups' },
[BRAND_TYPE_NAME]: { bulkPath: '/api/v1/brands' },
})

const customDefinitions: Record<string, Partial<InstanceDeployApiDefinitions>> = {
Expand Down
3 changes: 3 additions & 0 deletions packages/okta-adapter/src/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ export const defaultDeployChange = async (
}
}

if (apiDefinitions.types[getChangeData(change).elemID.typeName] === undefined) {
throw new Error(`No deployment configuration found for type ${getChangeData(change).elemID.typeName}`)
}
const { deployRequests } = apiDefinitions.types[getChangeData(change).elemID.typeName]
try {
const response = await deployment.deployChange({
Expand Down
80 changes: 76 additions & 4 deletions packages/okta-adapter/test/adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { accessTokenCredentialsType } from '../src/auth'
import { DEFAULT_CONFIG } from '../src/user_config'
import fetchMockReplies from './fetch_mock_replies.json'
import deployMockReplies from './deploy_mock_replies.json'
import { GROUP_TYPE_NAME, OKTA, USER_TYPE_NAME } from '../src/constants'
import { USER_TYPE_NAME, BRAND_TYPE_NAME, GROUP_TYPE_NAME, OKTA } from '../src/constants'

const nullProgressReporter: ProgressReporter = {
reportProgress: () => null,
Expand Down Expand Up @@ -454,7 +454,7 @@ describe('adapter', () => {
})
})

describe('deploy groups', () => {
describe('deploy group', () => {
let groupType: ObjectType
let group1: InstanceElement
beforeEach(() => {
Expand All @@ -467,7 +467,7 @@ describe('adapter', () => {
},
})
group1 = new InstanceElement('group1', groupType, {
id: 'fakeid123',
id: 'group-fakeid1',
objectClass: ['okta:user_group'],
type: 'OKTA_GROUP',
profile: {
Expand All @@ -489,7 +489,7 @@ describe('adapter', () => {
})
expect(result.errors).toHaveLength(0)
expect(result.appliedChanges).toHaveLength(1)
expect(getChangeData(result.appliedChanges[0] as Change<InstanceElement>).value.id).toEqual('fakeid123')
expect(getChangeData(result.appliedChanges[0] as Change<InstanceElement>).value.id).toEqual('group-fakeid1')
})

it('should successfully modify a group', async () => {
Expand Down Expand Up @@ -525,6 +525,78 @@ describe('adapter', () => {
})
})

describe('deploy brand', () => {
let brandType: ObjectType
let brand1: InstanceElement
beforeEach(() => {
brandType = new ObjectType({
elemID: new ElemID(OKTA, BRAND_TYPE_NAME),
fields: {
id: {
refType: BuiltinTypes.SERVICE_ID,
},
},
})
brand1 = new InstanceElement('brand1', brandType, {
id: 'brand-fakeid1',
name: 'subdomain.example.com',
removePoweredByOkta: false,
})
})

it('should successfully add a brand', async () => {
const brandWithoutId = new InstanceElement('brand1', brandType, {
name: 'subdomain.example.com',
removePoweredByOkta: false,
})
const result = await operations.deploy({
changeGroup: {
groupID: 'brand',
changes: [toChange({ after: brandWithoutId })],
},
progressReporter: nullProgressReporter,
})
expect(result.errors).toHaveLength(0)
expect(result.appliedChanges).toHaveLength(1)
expect(getChangeData(result.appliedChanges[0] as Change<InstanceElement>).value.id).toEqual('brand-fakeid1')
})

it('should successfully modify a brand', async () => {
const updatedBrand1 = brand1.clone()
updatedBrand1.value.removePoweredByOkta = true
const result = await operations.deploy({
changeGroup: {
groupID: 'brand',
changes: [
toChange({
before: brand1,
after: updatedBrand1,
}),
],
},
progressReporter: nullProgressReporter,
})

expect(result.errors).toHaveLength(0)
expect(result.appliedChanges).toHaveLength(1)
expect(getChangeData(result.appliedChanges[0] as Change<InstanceElement>).value.removePoweredByOkta).toEqual(
true,
)
})

it('should successfully remove a brand', async () => {
const result = await operations.deploy({
changeGroup: {
groupID: 'brand',
changes: [toChange({ before: brand1 })],
},
progressReporter: nullProgressReporter,
})
expect(result.errors).toHaveLength(0)
expect(result.appliedChanges).toHaveLength(1)
})
})

describe('deploy users', () => {
let userType: ObjectType
beforeEach(() => {
Expand Down
9 changes: 6 additions & 3 deletions packages/okta-adapter/test/deploy_mock_replies.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[
{"url":"/api/v1/groups","method":"POST","status":200,"response":{"id":"fakeid123","created":"2024-06-17T08:11:40.000Z","lastUpdated":"2024-06-17T08:11:40.000Z","lastMembershipUpdated":"2024-06-17T08:11:40.000Z","objectClass":["okta:user_group"],"type":"OKTA_GROUP","profile":{"name":"Engineers","description":"all the engineers"},"_links":{"logo":[{"name":"medium","href":"https://<sanitized>/assets/img/logos/groups/odyssey/okta-medium.30ce6d4085dff29412984e4c191bc874.png","type":"image/png"},{"name":"large","href":"https://<sanitized>/assets/img/logos/groups/odyssey/okta-large.c3cb8cda8ae0add1b4fe928f5844dbe3.png","type":"image/png"}],"owners":{"href":"https://<sanitized>/api/v1/groups/fakeid123/owners"},"users":{"href":"https://<sanitized>/api/v1/groups/fakeid123/users"},"apps":{"href":"https://<sanitized>/api/v1/groups/fakeid123/apps"}}},"headers":{"x-rate-limit-limit":"250","x-rate-limit-remaining":"249","x-rate-limit-reset":"1718611960"},"data":{"objectClass":["okta:user_group"],"type":"OKTA_GROUP","profile":{"name":"Engineers","description":"all the engineers"}}},
{"url":"/api/v1/groups/fakeid123","method":"PUT","status":200,"response":{"id":"fakeid123","created":"2024-06-17T08:11:40.000Z","lastUpdated":"2024-06-17T08:13:52.000Z","lastMembershipUpdated":"2024-06-17T08:11:40.000Z","objectClass":["okta:user_group"],"type":"OKTA_GROUP","profile":{"name":"Programmers","description":"all the engineers"},"_links":{"logo":[{"name":"medium","href":"https://<sanitized>/assets/img/logos/groups/odyssey/okta-medium.30ce6d4085dff29412984e4c191bc874.png","type":"image/png"},{"name":"large","href":"https://<sanitized>/assets/img/logos/groups/odyssey/okta-large.c3cb8cda8ae0add1b4fe928f5844dbe3.png","type":"image/png"}],"owners":{"href":"https://<sanitized>/api/v1/groups/fakeid123/owners"},"users":{"href":"https://<sanitized>/api/v1/groups/fakeid123/users"},"apps":{"href":"https://<sanitized>/api/v1/groups/fakeid123/apps"}}},"headers":{"x-rate-limit-limit":"500","x-rate-limit-remaining":"499","x-rate-limit-reset":"1718612092"},"data":{"id":"fakeid123","objectClass":["okta:user_group"],"type":"OKTA_GROUP","profile":{"name":"Programmers","description":"all the engineers"}}},
{"url":"/api/v1/groups/fakeid123","method":"DELETE","status":204,"response":"","headers":{"x-rate-limit-limit":"500","x-rate-limit-remaining":"499","x-rate-limit-reset":"1718612851"}},
{"url": "/api/v1/groups", "method": "POST", "status": 200, "response": { "id": "group-fakeid1", "created": "2024-06-17T08:11:40.000Z", "lastUpdated": "2024-06-17T08:11:40.000Z", "lastMembershipUpdated": "2024-06-17T08:11:40.000Z", "objectClass": [ "okta:user_group" ], "type": "OKTA_GROUP", "profile": { "name": "Engineers", "description": "all the engineers" }, "_links": { "logo": [ { "name": "medium", "href": "https://<sanitized>/assets/img/logos/groups/odyssey/okta-medium.30ce6d4085dff29412984e4c191bc874.png", "type": "image/png" }, { "name": "large", "href": "https://<sanitized>/assets/img/logos/groups/odyssey/okta-large.c3cb8cda8ae0add1b4fe928f5844dbe3.png", "type": "image/png" } ], "owners": { "href": "https://<sanitized>/api/v1/groups/group-fakeid1/owners" }, "users": { "href": "https://<sanitized>/api/v1/groups/group-fakeid1/users" }, "apps": { "href": "https://<sanitized>/api/v1/groups/group-fakeid1/apps" } } }, "headers": { "x-rate-limit-limit": "250", "x-rate-limit-remaining": "249", "x-rate-limit-reset": "1718611960" }, "data": { "objectClass": [ "okta:user_group" ], "type": "OKTA_GROUP", "profile": { "name": "Engineers", "description": "all the engineers" } } },
{"url": "/api/v1/groups/group-fakeid1", "method": "PUT", "status": 200, "response": { "id": "group-fakeid1", "created": "2024-06-17T08:11:40.000Z", "lastUpdated": "2024-06-17T08:13:52.000Z", "lastMembershipUpdated": "2024-06-17T08:11:40.000Z", "objectClass": [ "okta:user_group" ], "type": "OKTA_GROUP", "profile": { "name": "Programmers", "description": "all the engineers" }, "_links": { "logo": [ { "name": "medium", "href": "https://<sanitized>/assets/img/logos/groups/odyssey/okta-medium.30ce6d4085dff29412984e4c191bc874.png", "type": "image/png" }, { "name": "large", "href": "https://<sanitized>/assets/img/logos/groups/odyssey/okta-large.c3cb8cda8ae0add1b4fe928f5844dbe3.png", "type": "image/png" } ], "owners": { "href": "https://<sanitized>/api/v1/groups/group-fakeid1/owners" }, "users": { "href": "https://<sanitized>/api/v1/groups/group-fakeid1/users" }, "apps": { "href": "https://<sanitized>/api/v1/groups/group-fakeid1/apps" } } }, "headers": { "x-rate-limit-limit": "500", "x-rate-limit-remaining": "499", "x-rate-limit-reset": "1718612092" }, "data": { "id": "group-fakeid1", "objectClass": [ "okta:user_group" ], "type": "OKTA_GROUP", "profile": { "name": "Programmers", "description": "all the engineers" } } },
{"url": "/api/v1/groups/group-fakeid1", "method": "DELETE", "status": 204, "response": "", "headers": { "x-rate-limit-limit": "500", "x-rate-limit-remaining": "499", "x-rate-limit-reset": "1718612851" } },
{"url":"/api/v1/brands","method":"POST","status":201,"response":{"id":"brand-fakeid1","name":"subdomain4.salto.io","removePoweredByOkta":false,"customPrivacyPolicyUrl":null,"agreeToCustomPrivacyPolicy":false,"isDefault":false,"defaultApp":{"appInstanceId":null,"appLinkName":null,"classicApplicationUri":null},"_links":{"themes":{"href":"https://<sanitized>/api/v1/brands/brand-fakeid1/themes","hints":{"allow":["GET"]}},"self":{"href":"https://<sanitized>/api/v1/brands/brand-fakeid1","hints":{"allow":["GET","PUT","DELETE"]}}}},"headers":{"x-rate-limit-limit":"500","x-rate-limit-remaining":"497","x-rate-limit-reset":"1718631287"},"data":{"name":"subdomain4.salto.io","removePoweredByOkta":false,"agreeToCustomPrivacyPolicy":false,"isDefault":false,"defaultApp":{"appInstanceId":"0oa1ly9huEKlEScdB696"}}},
{"url":"/api/v1/brands/brand-fakeid1","method":"DELETE","status":204,"response":"","headers":{"x-rate-limit-limit":"500","x-rate-limit-remaining":"498","x-rate-limit-reset":"1718631287"}},
{"url":"/api/v1/brands/brand-fakeid1","method":"PUT","status":200,"response":{"id":"brand-fakeid1","name":"subdomain4.salto.io","removePoweredByOkta":true,"customPrivacyPolicyUrl":null,"agreeToCustomPrivacyPolicy":false,"isDefault":false,"defaultApp":{"appInstanceId":"0oa1ly9huEKlEScdB696","appLinkName":null,"classicApplicationUri":null},"_links":{"themes":{"href":"https://<sanitized>/api/v1/brands/brand-fakeid1/themes","hints":{"allow":["GET"]}},"self":{"href":"https://<sanitized>/api/v1/brands/brand-fakeid1","hints":{"allow":["GET","PUT","DELETE"]}}}},"headers":{"x-rate-limit-limit":"500","x-rate-limit-remaining":"498","x-rate-limit-reset":"1718632593"},"data":{"id":"brand-fakeid1","name":"subdomain4.salto.io","removePoweredByOkta":true,"agreeToCustomPrivacyPolicy":false,"isDefault":false,"defaultApp":{"appInstanceId":"0oa1ly9huEKlEScdB696"}}},
{"url":"/api/v1/users","method":"POST","status":200,"queryParams":{"activate":"false"},"response":{"id":"fakeid123","status":"STAGED","created":"2024-06-26T15:34:05.000Z","activated":null,"statusChanged":null,"lastLogin":null,"lastUpdated":"2024-06-26T15:34:05.000Z","passwordChanged":null,"type":{"id":"oty1lvvml15CT6qcl696"},"profile":{"login":"thismaildoesnotexist2@salto.io"},"credentials":{"provider":{"type":"OKTA","name":"OKTA"}}},"headers":{"x-rate-limit-limit":"300","x-rate-limit-remaining":"299","x-rate-limit-reset":"1719416105"}},
{"url":"/api/v1/users/fakeid123","method":"POST","status":200,"response":{"id":"fakeid123","status":"STAGED","created":"2024-06-26T14:43:31.000Z","activated":null,"statusChanged":null,"lastLogin":null,"lastUpdated":"2024-06-26T15:34:41.000Z","passwordChanged":null,"type":{"id":"oty1lvvml15CT6qcl696"},"profile":{"firstName":"modification","lastName":"test","manager":"new manager assigned","mobilePhone":null,"streetAddress":"salto io","city":"Tel Aviv","secondEmail":"","login":"thismaildoesnotexist@salto.io","email":"thismaildoesnotexist@salto.io"},"credentials":{"provider":{"type":"OKTA","name":"OKTA"}}},"headers":{"x-rate-limit-limit":"300","x-rate-limit-remaining":"299","x-rate-limit-reset":"1719416141"}},
{"url":"/api/v1/users/fakeid123/lifecycle/deactivate","method":"POST","status":200,"response":{},"headers":{"x-rate-limit-limit":"300","x-rate-limit-remaining":"298","x-rate-limit-reset":"1719416105"}},
Expand Down

0 comments on commit ec919e5

Please sign in to comment.