Skip to content

Commit

Permalink
fix: edit domain api cert expiry date returning null (#1531)
Browse files Browse the repository at this point in the history
* fix: edit domain api cert expiry date returning null

* refactor: remove var

---------

Co-authored-by: rjbrache <[email protected]>
Co-authored-by: Matt Primrose <[email protected]>
  • Loading branch information
3 people authored Apr 29, 2024
1 parent 344b1f1 commit 4eee76b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 86 deletions.
12 changes: 12 additions & 0 deletions src/certManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,16 @@ describe('certManager tests', () => {
expect(generateLeafCertificateSpy).toHaveBeenCalled()
})
})

describe('getExpirationDate tests', () => {
test('should retrieve the correct expiry date', () => {
const nodeForge = new NodeForge()
const certManager = new CertManager(new Logger('CertManager'), nodeForge)
const provisioningCert = 'MIIPHwIBAzCCDtUGCSqGSIb3DQEHAaCCDsYEgg7CMIIOvjCCCTIGCSqGSIb3DQEHBqCCCSMwggkfAgEAMIIJGAYJKoZIhvcNAQcBMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAiez5X6uaJNRwICCAAwDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFxT8M8aNmQ21VBJmNP10/mAggiwRGvio668bHHlIDpETQmJHvzEYnF3ou1Z5JkK8RCAdXbD5rkJuoQ6mzEZeyjtE2i4X0RMqVVZ+lfYUMoEysMxjccN87xGfrNvkM4En18E0xnxEcxINQmdRiqB8EniQnaLIdN4Mo7XHH0L3eqbA5ikYzDD3Do4OiGWLIMX5OCJHapR74pOcOglrcVL+QJ2blDBpIzFstgY15DYf7sxEiQPRwlccqaB0FjSxbaz9pZdE8U/dddgReJOTggB+dF5KwkntHF/CAmgAwwaORlRiA13RTRJGcuhjZ+bV9z/WmEfGqEvxAHqfgwXIoNvEpDWO/UEuuf+0Aq0uLLEebtkxfF0LHY+2Pnmw+KB9ECQdMv9GlX8LtTEGJZ8r+KquKjUcC1VNFbrCuoQxmaFNvtcpHDUcmfIzvRFWD5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chH+pxSA4ju8ItvGZhy4hof123yxf8Yh4LE5HjvTfG0h9gHqJRAoUH7k8PG1jElMCMGCSqGSIb3DQEJFTEWBBQQ121XP0QcupPfyzRfFXFWVYQnPjBBMDEwDQYJYIZIAWUDBAIBBQAEIG7DUtDht1xHJ77sCWv/Gu/2n+Ecv5Zfl3TTSYF5VzlfBAhEnK6i8ASSZwICCAA='
const provisioningCertPassword = 'P@ssw0rd'
const expectedExpDate = new Date('2033-05-03T07:11:10.000Z')
const result = certManager.getExpirationDate(provisioningCert, provisioningCertPassword)
expect(result).toEqual(expectedExpDate)
})
})
})
11 changes: 11 additions & 0 deletions src/certManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,15 @@ export class CertManager {
key: keys?.privateKey
}
}

getExpirationDate (cert: string, password: string): Date {
const pfxobj = this.convertPfxToObject(cert, password)
let expiresFirst = pfxobj.certs[0].validity.notAfter
for (const cert of pfxobj.certs) {
if (cert.validity.notAfter < expiresFirst) {
expiresFirst = cert.validity.notAfter
}
}
return expiresFirst
}
}
15 changes: 4 additions & 11 deletions src/routes/admin/domains/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ describe('Domain - Create', () => {
let insertSpy: SpyInstance<any>
let secretManagerSpy: SpyInstance<any>
let dc: DomainCreate
let dcReal: DomainCreate

beforeEach(() => {
resSpy = createSpyObj('Response', ['status', 'json', 'end', 'send'])
Expand All @@ -23,7 +22,10 @@ describe('Domain - Create', () => {
secretsManager: {
writeSecretWithObject: jest.fn()
},
body: { },
body: {
provisioningCert: 'MIIPHwIBAzCCDtUGCSqGSIb3DQEHAaCCDsYEgg7CMIIOvjCCCTIGCSqGSIb3DQEHBqCCCSMwggkfAgEAMIIJGAYJKoZIhvcNAQcBMFcGCSqGSIb3DQEFDTBKMCkGCSqGSIb3DQEFDDAcBAiez5X6uaJNRwICCAAwDAYIKoZIhvcNAgkFADAdBglghkgBZQMEASoEEFxT8M8aNmQ21VBJmNP10/mAgg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ILJCyQMDr/7V+wucSHeAqEx2RJx8o9cx7gkfCNnqCt9/UW96bbnnlLpYuUou5R6QyWMxqTSp+s8EgBtXNLaKcjt0gjmEhieAl55LmZn0ePxSJjYyF3AYO1tvxT4wWrLdiAA/Kj7mZcOdpisdjzIJdt9JgMjdmuCiJPvrujcj4rpEyhsBgDTe39eSEWe86yxsUewnacMClv/gmk/8p5sssyjETIEgSiGJxXG3DUcqlJ2nXFlgMojU9XEXir02GlxGzm1QE6USIJZ2d4HT0TAEq8qGssLoWQ+FKGHmbc9Qmm6Own0T6YVAzTJ+llj2dosTo5PT1pM06VyEgVcaREM2PLBZYju0NpRs14hYyQ24039URFa5pmnaYvcQvv3c3U/zlnAKgO6Cpyo3aby+Zrk9z6534YVIgPjNMF7Wp3MYchH+pxSA4ju8ItvGZhy4hof123yxf8Yh4LE5HjvTfG0h9gHqJRAoUH7k8PG1jElMCMGCSqGSIb3DQEJFTEWBBQQ121XP0QcupPfyzRfFXFWVYQnPjBBMDEwDQYJYIZIAWUDBAIBBQAEIG7DUtDht1xHJ77sCWv/Gu/2n+Ecv5Zfl3TTSYF5VzlfBAhEnK6i8ASSZwICCAA=',
provisioningCertPassword: 'P@ssw0rd'
},
query: { }
}
insertSpy = spyOn(req.db.domains, 'insert').mockResolvedValue({ })
Expand All @@ -32,8 +34,6 @@ describe('Domain - Create', () => {
resSpy.json.mockReturnThis()
resSpy.send.mockReturnThis()
dc = new DomainCreate()
dcReal = new DomainCreate()
spyOn(dc, 'getExpirationDate').mockReturnValue(new Date())
})
it('should create', async () => {
await dc.createDomain(req, resSpy)
Expand Down Expand Up @@ -68,11 +68,4 @@ describe('Domain - Create', () => {
await dc.createDomain(req, resSpy)
expect(resSpy.status).toHaveBeenCalledWith(201)
})
it('should create even when no secretsManager', async () => {
const provisioningCert = 'MIIPHwIBAzCCDtUGCSqGSIb3DQEHAaCCDsYEgg7CMIIOvjCCCTIGCSqGSIb3DQEHBqCCCSMwggkfAgEAMIIJGAYJKoZIhv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FtrMxMSl2L7focRac4Ns7hpd+Ac/q841kescsMAtFPeJcxMans8nTylfhiB+1+e2Sikydy6+ZLT96GZLLDm3uSEwkxgNHtB2eAkv6dPk83rpN1DjLsj8pUu4eh6CuqwqohuILJCyQMDr/7V+wucSHeAqEx2RJx8o9cx7gkfCNnqCt9/UW96bbnnlLpYuUou5R6QyWMxqTSp+s8EgBtXNLaKcjt0gjmEhieAl55LmZn0ePxSJjYyF3AYO1tvxT4wWrLdiAA/Kj7mZcOdpisdjzIJdt9JgMjdmuCiJPvrujcj4rpEyhsBgDTe39eSEWe86yxsUewnacMClv/gmk/8p5sssyjETIEgSiGJxXG3DUcqlJ2nXFlgMojU9XEXir02GlxGzm1QE6USIJZ2d4HT0TAEq8qGssLoWQ+FKGHmbc9Qmm6Own0T6YVAzTJ+llj2dosTo5PT1pM06VyEgVcaREM2PLBZYju0NpRs14hYyQ24039URFa5pmnaYvcQvv3c3U/zlnAKgO6Cpyo3aby+Zrk9z6534YVIgPjNMF7Wp3MYchH+pxSA4ju8ItvGZhy4hof123yxf8Yh4LE5HjvTfG0h9gHqJRAoUH7k8PG1jElMCMGCSqGSIb3DQEJFTEWBBQQ121XP0QcupPfyzRfFXFWVYQnPjBBMDEwDQYJYIZIAWUDBAIBBQAEIG7DUtDht1xHJ77sCWv/Gu/2n+Ecv5Zfl3TTSYF5VzlfBAhEnK6i8ASSZwICCAA='
const provisioningCertPassword = 'P@ssw0rd'
const expectedExpDate = new Date('2033-05-03T07:11:10.000Z')

expect(dcReal.getExpirationDate(provisioningCert, provisioningCertPassword)).toEqual(expectedExpDate)
})
})
19 changes: 3 additions & 16 deletions src/routes/admin/domains/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class DomainCreate {
const log = new Logger('createDomain')
let cert: string = ''
let domainPwd: string = ''
const nodeForge = new NodeForge()
const certManager = new CertManager(new Logger('CertManager'), nodeForge)
try {
// store the cert and password key in database
if (req.secretsManager) {
Expand All @@ -29,7 +31,7 @@ export class DomainCreate {
}
amtDomain.provisioningCert = 'CERT'
amtDomain.provisioningCertPassword = 'CERT_PASSWORD'
amtDomain.expirationDate = this.getExpirationDate(cert, domainPwd)
amtDomain.expirationDate = certManager.getExpirationDate(cert, domainPwd)
}
// SQL Query > Insert Data
const results: AMTDomain | null = await req.db.domains.insert(amtDomain)
Expand Down Expand Up @@ -63,19 +65,4 @@ export class DomainCreate {
handleError(log, amtDomain.profileName, req, res, error)
}
}

public getExpirationDate (cert: string, password: string): Date {
const nodeForge = new NodeForge()
const certManager = new CertManager(new Logger('CertManager'), nodeForge)
const pfxobj = certManager.convertPfxToObject(cert, password)

let expiresFirst = pfxobj.certs[0].validity.notAfter
for (const cert of pfxobj.certs) {
if (cert.validity.notAfter < expiresFirst) {
expiresFirst = cert.validity.notAfter
}
}

return expiresFirst
}
}
Loading

0 comments on commit 4eee76b

Please sign in to comment.