Skip to content

Commit

Permalink
fix(redir): improve data checking for redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-primrose committed Oct 23, 2023
1 parent 9651c93 commit 7aa1510
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/secrets/vault/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ test('should return null if AMT credentials for a specific device does not exist
expect(secretAtPathSpy).toHaveBeenCalledWith(`devices/${secretPath}`)
})

test('should return null if AMT_Password for a specific device does not exists', async () => {
const noCredential = {
data: {
data: {
MEBX_PASSWORD: 'Intel@123',
MPS_PASSWORD: 'lLJPJNtU2$8FZTUy'
}
}
}
const secretAtPathSpy = jest.spyOn(secretManagerService, 'getSecretAtPath').mockResolvedValue(noCredential.data)
const result = await secretManagerService.getAMTCredentials(secretPath)
expect(result).toEqual(null)
expect(secretAtPathSpy).toHaveBeenCalledWith(`devices/${secretPath}`)
})

test('should return null if secret data for a specific device does not exists', async () => {
const noCredential = {
data: { }
}
const secretAtPathSpy = jest.spyOn(secretManagerService, 'getSecretAtPath').mockResolvedValue(noCredential.data)
const result = await secretManagerService.getAMTCredentials(secretPath)
expect(result).toEqual(null)
expect(secretAtPathSpy).toHaveBeenCalledWith(`devices/${secretPath}`)
})

test('should get MPS certs', async () => {
const secretAtPathSpy = jest.spyOn(secretManagerService, 'getSecretAtPath').mockResolvedValue(secretCert)
const result = await secretManagerService.getMPSCerts()
Expand Down
2 changes: 1 addition & 1 deletion src/secrets/vault/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class VaultSecretManagerService implements ISecretManagerService {
async getAMTCredentials (path: string): Promise<string[]> {
const user = 'admin'
const secret: { data: DeviceSecrets } = await this.getSecretAtPath(`devices/${path}`)
if (secret == null) {
if (secret?.data?.AMT_PASSWORD == null) {
return null
}
const amtpass: string = secret.data.AMT_PASSWORD
Expand Down
20 changes: 20 additions & 0 deletions src/utils/wsRedirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ describe('WsRedirect tests', () => {
wsRedirect.createCredential(paramsWithPof2 as any, credentials)
expect(wsRedirect.interceptor).toBeFalsy()
})

it('should not create credential if any are missing', () => {
const paramsWithPof2 = {
p: 2
}
const credentials = ['test']

wsRedirect.createCredential(paramsWithPof2 as any, credentials)
expect(wsRedirect.interceptor).toBeFalsy()
})

it('should not create credential too many are passed in', () => {
const paramsWithPof2 = {
p: 2
}
const credentials = ['test1', 'test2', 'test3']

wsRedirect.createCredential(paramsWithPof2 as any, credentials)
expect(wsRedirect.interceptor).toBeFalsy()
})
})

describe('setnormalTCP test', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/wsRedirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class WsRedirect {
}

createCredential (params: queryParams, credentials: string[]): void {
if (credentials != null) {
if (credentials?.length === 2 && credentials[0] != null && credentials[1] != null) {
logger.debug(messages.REDIRECT_CREATING_CREDENTIAL)
if (params.p === 2) {
this.interceptor = new RedirectInterceptor({
Expand Down

0 comments on commit 7aa1510

Please sign in to comment.