Skip to content

Commit 7d40bd2

Browse files
committed
chore: remove audit user since it cannot be shown in ui
1 parent 204066c commit 7d40bd2

3 files changed

Lines changed: 2 additions & 147 deletions

File tree

src/commands/app/deploy.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const {
2626
const rtLib = require('@adobe/aio-lib-runtime')
2727
const LogForwarding = require('../../lib/log-forwarding')
2828
const { sendAppAssetsDeployedAuditLog, sendAppDeployAuditLog } = require('../../lib/audit-logger')
29-
const { setRuntimeApiHostAndAuthHandler, getAccessToken, getTokenData } = require('../../lib/auth-helper')
29+
const { setRuntimeApiHostAndAuthHandler, getAccessToken } = require('../../lib/auth-helper')
3030
const logActions = require('../../lib/log-actions')
3131

3232
const PRE_DEPLOY_EVENT_REG = 'pre-deploy-event-reg'
@@ -68,8 +68,6 @@ class Deploy extends BuildCommand {
6868

6969
if (cliDetails?.accessToken) {
7070
try {
71-
// store user id from token data for cdn deploy audit metadata
72-
appInfo.auditUserId = getTokenData(cliDetails.accessToken)?.user_id
7371
// send audit log at start (don't wait for deployment to finish)
7472
await sendAppDeployAuditLog({
7573
accessToken: cliDetails?.accessToken,
@@ -132,10 +130,7 @@ class Deploy extends BuildCommand {
132130
// - break into smaller pieces deploy, allowing to first deploy all actions then all web assets
133131
for (let i = 0; i < keys.length; ++i) {
134132
const k = keys[i]
135-
// auditUserId is only set if it is available in the token data
136-
// falsy because "", 0, false, null, undefined, NaN, etc. are all invalid values
137133
const v = {
138-
...(appInfo.auditUserId && { auditUserId: appInfo.auditUserId }),
139134
...setRuntimeApiHostAndAuthHandler(values[i])
140135
}
141136
await this.deploySingleConfig({ name: k, config: v, originalConfig: values[i], flags, spinner })

test/commands/app/deploy.test.js

Lines changed: 1 addition & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ beforeEach(() => {
198198
env: 'stage'
199199
}
200200
})
201-
authHelper.getTokenData.mockImplementation(() => {
202-
return null // default to null, tests can override
203-
})
201+
204202
LogForwarding.init.mockResolvedValue(mockLogForwarding)
205203

206204
command = new TheCommand([])
@@ -673,136 +671,6 @@ describe('run', () => {
673671
expect(open).toHaveBeenCalledWith('http://prefix?fake=https://example.com')
674672
})
675673

676-
test('deploy should pass auditUserId to deployWeb config when user_id is present in token', async () => {
677-
const mockUserId = 'test-user-123'
678-
const mockToken = 'mock.token.value'
679-
680-
authHelper.getAccessToken.mockResolvedValueOnce({
681-
accessToken: mockToken,
682-
env: 'stage'
683-
})
684-
authHelper.getTokenData.mockReturnValueOnce({
685-
user_id: mockUserId
686-
})
687-
688-
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
689-
mockWebLib.deployWeb.mockResolvedValue('https://example.com')
690-
691-
command.argv = []
692-
await command.run()
693-
694-
expect(command.error).toHaveBeenCalledTimes(0)
695-
expect(authHelper.getTokenData).toHaveBeenCalledWith(mockToken)
696-
expect(mockWebLib.deployWeb).toHaveBeenCalledWith(
697-
expect.objectContaining({
698-
auditUserId: mockUserId
699-
}),
700-
expect.any(Function)
701-
)
702-
})
703-
704-
test('deploy should NOT include auditUserId in config when user_id is undefined', async () => {
705-
const mockToken = 'mock.token.value'
706-
707-
authHelper.getAccessToken.mockResolvedValueOnce({
708-
accessToken: mockToken,
709-
env: 'stage'
710-
})
711-
authHelper.getTokenData.mockReturnValueOnce({
712-
// user_id is undefined
713-
})
714-
715-
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
716-
mockWebLib.deployWeb.mockResolvedValue('https://example.com')
717-
718-
command.argv = []
719-
await command.run()
720-
721-
expect(command.error).toHaveBeenCalledTimes(0)
722-
expect(mockWebLib.deployWeb).toHaveBeenCalledWith(
723-
expect.not.objectContaining({
724-
auditUserId: expect.anything()
725-
}),
726-
expect.any(Function)
727-
)
728-
})
729-
730-
test('deploy should NOT include auditUserId in config when user_id is null', async () => {
731-
const mockToken = 'mock.token.value'
732-
733-
authHelper.getAccessToken.mockResolvedValueOnce({
734-
accessToken: mockToken,
735-
env: 'stage'
736-
})
737-
authHelper.getTokenData.mockReturnValueOnce({
738-
user_id: null
739-
})
740-
741-
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
742-
mockWebLib.deployWeb.mockResolvedValue('https://example.com')
743-
744-
command.argv = []
745-
await command.run()
746-
747-
expect(command.error).toHaveBeenCalledTimes(0)
748-
expect(mockWebLib.deployWeb).toHaveBeenCalledWith(
749-
expect.not.objectContaining({
750-
auditUserId: expect.anything()
751-
}),
752-
expect.any(Function)
753-
)
754-
})
755-
756-
test('deploy should NOT include auditUserId in config when user_id is empty string', async () => {
757-
const mockToken = 'mock.token.value'
758-
759-
authHelper.getAccessToken.mockResolvedValueOnce({
760-
accessToken: mockToken,
761-
env: 'stage'
762-
})
763-
authHelper.getTokenData.mockReturnValueOnce({
764-
user_id: ''
765-
})
766-
767-
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
768-
mockWebLib.deployWeb.mockResolvedValue('https://example.com')
769-
770-
command.argv = []
771-
await command.run()
772-
773-
expect(command.error).toHaveBeenCalledTimes(0)
774-
expect(mockWebLib.deployWeb).toHaveBeenCalledWith(
775-
expect.not.objectContaining({
776-
auditUserId: expect.anything()
777-
}),
778-
expect.any(Function)
779-
)
780-
})
781-
782-
test('deploy should NOT include auditUserId when getTokenData returns null', async () => {
783-
const mockToken = 'mock.token.value'
784-
785-
authHelper.getAccessToken.mockResolvedValueOnce({
786-
accessToken: mockToken,
787-
env: 'stage'
788-
})
789-
authHelper.getTokenData.mockReturnValueOnce(null)
790-
791-
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
792-
mockWebLib.deployWeb.mockResolvedValue('https://example.com')
793-
794-
command.argv = []
795-
await command.run()
796-
797-
expect(command.error).toHaveBeenCalledTimes(0)
798-
expect(mockWebLib.deployWeb).toHaveBeenCalledWith(
799-
expect.not.objectContaining({
800-
auditUserId: expect.anything()
801-
}),
802-
expect.any(Function)
803-
)
804-
})
805-
806674
test('deploy should show action urls (web-export: true)', async () => {
807675
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
808676
mockRuntimeLib.deployActions.mockResolvedValue({

test/commands/lib/auth-helper.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ describe('getTokenData', () => {
6161
beforeEach(() => {
6262
jest.clearAllMocks()
6363
})
64-
65-
test('should call through to getImsTokenData to decode JWT token and return payload', () => {
66-
getImsTokenData.mockReturnValue({ user_id: '12345', name: 'Test User' })
67-
// Example JWT token with payload: {"user_id":"12345","name":"Test User"}
68-
const exampleToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMTIzNDUiLCJuYW1lIjoiVGVzdCBVc2VyIn0.sflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c'
69-
const result = getTokenData(exampleToken)
70-
expect(result).toEqual({ user_id: '12345', name: 'Test User' })
71-
})
7264
test('should return null for invalid token', () => {
7365
getImsTokenData.mockImplementation(() => { throw new Error('Invalid token') })
7466
const invalidToken = 'invalid.token.string'

0 commit comments

Comments
 (0)