Skip to content

Commit 59199b5

Browse files
David-Kunzsjvans
andauthored
fix: json instead of josn (#18)
* fix: json instead of josn * Unauthorized * fix * Unauthorized --------- Co-authored-by: sjvans <[email protected]> Co-authored-by: D050513 <[email protected]>
1 parent 3491c47 commit 59199b5

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cds-plugin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ function _validateCertificate(req, res, next) {
6969

7070
if (req.headers['x-ssl-client-verify'] !== '0') {
7171
this.LOG.info('cf did not validate client certificate.')
72-
return res.status(401).json({ message: 'Authentication Failed' })
72+
return res.status(401).json({ message: 'Unauthorized' })
7373
}
7474

7575
if (!req.headers['x-forwarded-client-cert']) {
7676
this.LOG.info('no certificate in xfcc header.')
77-
return res.status(401).json({ message: 'Authentication Failed' })
77+
return res.status(401).json({ message: 'Unauthorized' })
7878
}
7979

8080
const clientCertObj = new crypto.X509Certificate(
@@ -83,33 +83,33 @@ function _validateCertificate(req, res, next) {
8383
const clientCert = clientCertObj.toLegacyObject()
8484

8585
if (!this.isMultitenancy && !clientCertObj.checkPrivateKey(this.auth.privateKey))
86-
return res.status(401).josn({ message: 'Authentication Failed' })
86+
return res.status(401).json({ message: 'Unauthorized' })
8787

8888
const cfSubject = Buffer.from(req.headers['x-ssl-client-subject-cn'], 'base64').toString()
8989
if (
9090
this.auth.validationCert.subject.CN !== clientCert.subject.CN ||
9191
this.auth.validationCert.subject.CN !== cfSubject
9292
) {
9393
this.LOG.info('certificate subject does not match')
94-
return res.status(401).json({ message: 'Authentication Failed' })
94+
return res.status(401).json({ message: 'Unauthorized' })
9595
}
9696
this.LOG.debug('incoming Subject CN is valid.')
9797

9898
if (this.auth.validationCert.issuer.CN !== clientCert.issuer.CN) {
9999
this.LOG.info('Certificate issuer subject does not match')
100-
return res.status(401).json({ message: 'Authentication Failed' })
100+
return res.status(401).json({ message: 'Unauthorized' })
101101
}
102102
this.LOG.debug('incoming issuer subject CN is valid.')
103103

104104
if (this.auth.validationCert.issuer.O !== clientCert.issuer.O) {
105105
this.LOG.info('Certificate issuer org does not match')
106-
return res.status(401).json({ message: 'Authentication Failed' })
106+
return res.status(401).json({ message: 'Unauthorized' })
107107
}
108108
this.LOG.debug('incoming Issuer Org is valid.')
109109

110110
if (this.auth.validationCert.issuer.OU !== clientCert.issuer.OU) {
111111
this.LOG.info('certificate issuer OU does not match')
112-
return res.status(401).json({ message: 'Authentication Failed' })
112+
return res.status(401).json({ message: 'Unauthorized' })
113113
}
114114
this.LOG.debug('certificate issuer OU is valid.')
115115

@@ -121,7 +121,7 @@ function _validateCertificate(req, res, next) {
121121
next()
122122
} else {
123123
this.LOG.error('Certificate expired')
124-
return res.status(401).json({ message: 'Authentication Failed' })
124+
return res.status(401).json({ message: 'Unauthorized' })
125125
}
126126
}
127127

@@ -291,7 +291,7 @@ class EventBroker extends cds.MessagingService {
291291
cds.app.use(webhookBasePath, cds.middlewares.context())
292292
cds.app.use(webhookBasePath, ias_auth(this.auth.ias))
293293
cds.app.use(webhookBasePath, (err, _req, res, next) => {
294-
if (err.code === 401) return res.status(401).json({ message: 'Unauthorized' })
294+
if (err == 401 || err.code == 401) return res.status(401).json({ message: 'Unauthorized' })
295295
return next(err)
296296
})
297297
cds.app.use(webhookBasePath, (_req, res, next) => {

0 commit comments

Comments
 (0)