Skip to content

Commit 353afcb

Browse files
committed
Fixed tslint errors
1 parent 1ed1990 commit 353afcb

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/JwtHandler.spec.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ describe("JwtHandler", () => {
6161
it("should return the JWT body if passed a valid JWT", (done) => {
6262
const jwtRaw = generateJwt(keyId, tokenBody)
6363
expect(
64-
jwtHandler.verify(jwtRaw),
64+
jwtHandler.verify(jwtRaw)
6565
).to.eventually.deep.equal(tokenBody).notify(done)
6666
})
6767

6868
it("should return the JWT body if passed a valid JWT and validation options that matches the JWT", (done) => {
6969
const jwtRaw = generateJwt(keyId, tokenBody)
7070
expect(
71-
jwtHandler.verify(jwtRaw, {issuer: tokenBody.iss}),
71+
jwtHandler.verify(jwtRaw, {issuer: tokenBody.iss})
7272
).to.eventually.deep.equal(tokenBody).notify(done)
7373
})
7474

7575
it("should be rejected with JsonWebTokenError if the validation options do not match", (done) => {
7676
const jwtRaw = generateJwt(keyId, tokenBody)
7777
expect(
78-
jwtHandler.verify(jwtRaw, {issuer: "expected_issuer"}),
78+
jwtHandler.verify(jwtRaw, {issuer: "expected_issuer"})
7979
).to.eventually.rejectedWith(jwt.JsonWebTokenError).notify(done)
8080
})
8181

@@ -87,7 +87,7 @@ describe("JwtHandler", () => {
8787
}
8888
const jwtRaw = generateJwt(keyId, tokenBodyExpired)
8989
expect(
90-
jwtHandler.verify(jwtRaw),
90+
jwtHandler.verify(jwtRaw)
9191
).to.eventually.rejectedWith(jwt.TokenExpiredError).notify(done)
9292
})
9393

@@ -99,47 +99,48 @@ describe("JwtHandler", () => {
9999
}
100100
const jwtRaw = generateJwt(keyId, tokenBodyNbf)
101101
expect(
102-
jwtHandler.verify(jwtRaw),
102+
jwtHandler.verify(jwtRaw)
103103
).to.eventually.rejectedWith(jwt.NotBeforeError).notify(done)
104104
})
105105

106106
it("should be rejected with JsonWebTokenError if the JWT is empty", (done) => {
107107
expect(
108-
jwtHandler.verify(""),
108+
jwtHandler.verify("")
109109
).to.be.rejectedWith(jwt.JsonWebTokenError).notify(done)
110110
})
111111

112112
it("should be rejected with JsonWebTokenError if the JWT is null", (done) => {
113113
expect(
114-
jwtHandler.verify(null as any),
114+
jwtHandler.verify(null as any)
115115
).to.be.rejectedWith(jwt.JsonWebTokenError).notify(done)
116116
})
117117

118118
it("should be rejected with JsonWebTokenError if the JWT is undefined", (done) => {
119119
expect(
120-
jwtHandler.verify(undefined as any),
120+
jwtHandler.verify(undefined as any)
121121
).to.be.rejectedWith(jwt.JsonWebTokenError).notify(done)
122122
})
123123

124+
// tslint:disable-next-line:max-line-length
124125
it("should be rejected with MissingKeyIdError if the JWT does not contain a kid property in the header", (done) => {
125126
const jwtRaw = generateJwt(null, tokenBody)
126127
expect(
127-
jwtHandler.verify(jwtRaw),
128+
jwtHandler.verify(jwtRaw)
128129
).to.eventually.rejectedWith(MissingKeyIdError).notify(done)
129130
})
130131

131132
it("should be rejected with UnknownKeyIdError if the key id is unknown", (done) => {
132133
const jwtRaw = generateJwt("unknown-key-id", tokenBody)
133134
expect(
134-
jwtHandler.verify(jwtRaw),
135+
jwtHandler.verify(jwtRaw)
135136
).to.eventually.rejectedWith(UnknownKeyIdError).notify(done)
136137
})
137138

138139
it("should be throw an Error if no pubkey resolver is specified", (done) => {
139140
const jwtHandlerNoPubkeyResolver = new JwtHandler(debugNamePrefix, null, privkeyResolver)
140141
const jwtRaw = generateJwt(keyId, tokenBody)
141142
expect(
142-
jwtHandlerNoPubkeyResolver.verify(jwtRaw),
143+
jwtHandlerNoPubkeyResolver.verify(jwtRaw)
143144
).to.eventually.rejectedWith(Error).notify(done)
144145
})
145146
})
@@ -150,21 +151,21 @@ describe("JwtHandler", () => {
150151
jwtHandler.create(tokenBody, keyId)
151152
.then((result) => {
152153
expect(
153-
result.match(/^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/),
154+
result.match(/^[a-zA-Z0-9\-_]+?\.[a-zA-Z0-9\-_]+?\.([a-zA-Z0-9\-_]+)?$/)
154155
).to.be.instanceof(Array)
155156
done()
156157
})
157158
})
158159
it("should be rejected with UnknownKeyIdError with a key id that does not exist", (done) => {
159160
const keyIdUnknown = "unknown-key-id"
160161
expect(
161-
jwtHandler.create(tokenBody, keyIdUnknown),
162+
jwtHandler.create(tokenBody, keyIdUnknown)
162163
).to.be.rejectedWith(UnknownKeyIdError).notify(done)
163164
})
164165
it("should be rejected with Error if no privkey resolver is specified", (done) => {
165166
const jwtHandlerNoPrivkeyResolver = new JwtHandler(debugNamePrefix, pubkeyResolver, null)
166167
expect(
167-
jwtHandlerNoPrivkeyResolver.create(tokenBody, keyId),
168+
jwtHandlerNoPrivkeyResolver.create(tokenBody, keyId)
168169
).to.be.rejectedWith(Error).notify(done)
169170
})
170171
// it("should be rejected with UnknownKeyIdError with a null key id", (done) => {
@@ -179,7 +180,7 @@ function generateJwt(kid: string | null, body: object) {
179180
const header = kid ? {kid} : undefined
180181
return jwt.sign(body, {
181182
key: privateKey, passphrase: privateKeyPass,
182-
}, {algorithm: "RS256", header},
183+
}, {algorithm: "RS256", header}
183184
)
184185
}
185186

src/JwtHandler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type PrivkeyData = { key: string, passphrase: string, alg: string } | und
1414
export type PubkeyResolver = (keyId: string) => PubkeyData | Promise<PubkeyData>
1515
export type PrivkeyResolver = (keyId: string) => PrivkeyData | Promise<PrivkeyData>
1616

17+
// tslint:disable-next-line:max-line-length
1718
type JwtVerifyAsync = (token: string, publicKey: string | Buffer, options?: jwt.VerifyOptions) => Promise<object | string>
1819
type JwtSignAsync = (payload: string | Buffer | object, privateKey: {}, options?: jwt.SignOptions) => Promise<string>
1920

0 commit comments

Comments
 (0)