Skip to content

Commit f1a436f

Browse files
gugucjbarth
andauthored
Tests use typescript (#534)
Co-authored-by: Chris Barth <[email protected]>
1 parent ed4be0c commit f1a436f

21 files changed

+1058
-832
lines changed

.eslintrc renamed to .eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"env": {
33
"node": true,
4+
"mocha": true,
45
"es6": false
56
},
67
"root": true,
@@ -9,7 +10,6 @@
910
"parserOptions": {
1011
"ecmaVersion": 6
1112
},
12-
1313
"extends": [
1414
"eslint:recommended",
1515
"plugin:@typescript-eslint/eslint-recommended",

.gitignore

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
lib
2-
node_modules/
3-
.tern-port
4-
.idea
5-
yarn-error.log
6-
.DS_Store
1+
lib
2+
node_modules/
3+
.tern-port
4+
.idea
5+
yarn-error.log
6+
.DS_Store
7+
.eslintcache

.mocharc.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"diff": true,
3+
"extension": "spec.ts",
4+
"package": "./package.json",
5+
"reporter": "spec",
6+
"require": ["choma", "ts-node/register"],
7+
"files": "test/**/*.spec.ts",
8+
"watch-files": "test/**/*.spec.ts"
9+
}

.prettierignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
# Ignore artifacts:
2-
node_modules
3-
lib
1+
# Ignore artifacts:
2+
node_modules
3+
lib
4+
package-lock.json

package-lock.json

+112
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"scripts": {
3838
"build": "tsc",
3939
"changelog": "gren changelog --override --generate",
40-
"lint": "eslint --ext .ts src",
40+
"lint": "eslint --ext .ts **/*.ts --cache",
4141
"lint-watch": "onchange -k -p 100 \"**/*.ts\" -- eslint {{file}}",
4242
"lint:fix": "eslint --ext .ts --fix src",
4343
"prepare": "tsc",
@@ -60,8 +60,11 @@
6060
},
6161
"devDependencies": {
6262
"@types/debug": "^4.1.5",
63+
"@types/mocha": "^8.2.0",
6364
"@types/node": "^14.14.13",
6465
"@types/passport-strategy": "^0.2.35",
66+
"@types/request": "^2.48.5",
67+
"@types/sinon": "^9.0.10",
6568
"@types/xml-crypto": "^1.4.1",
6669
"@types/xml-encryption": "^1.2.0",
6770
"@types/xml2js": "^0.4.7",
@@ -85,6 +88,7 @@
8588
"request": "^2.83.0",
8689
"should": "*",
8790
"sinon": "^9.2.2",
91+
"ts-node": "^9.1.1",
8892
"typescript": "^4.1.3"
8993
},
9094
"engines": {

src/passport-saml/algorithms.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
import * as crypto from "crypto";
22

3-
export function getSigningAlgorithm(shortName: string): string {
3+
export function getSigningAlgorithm(shortName?: string): string {
44
switch (shortName) {
55
case "sha256":
66
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
77
case "sha512":
88
return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512";
9+
case "sha1":
910
default:
1011
return "http://www.w3.org/2000/09/xmldsig#rsa-sha1";
1112
}
1213
}
1314

14-
export function getDigestAlgorithm(shortName: string): string {
15+
export function getDigestAlgorithm(shortName?: string): string {
1516
switch (shortName) {
1617
case "sha256":
1718
return "http://www.w3.org/2001/04/xmlenc#sha256";
1819
case "sha512":
1920
return "http://www.w3.org/2001/04/xmlenc#sha512";
21+
case "sha1":
2022
default:
2123
return "http://www.w3.org/2000/09/xmldsig#sha1";
2224
}
2325
}
2426

25-
export function getSigner(shortName: string): crypto.Signer {
27+
export function getSigner(shortName?: string): crypto.Signer {
2628
switch (shortName) {
2729
case "sha256":
2830
return crypto.createSign("RSA-SHA256");
2931
case "sha512":
3032
return crypto.createSign("RSA-SHA512");
33+
case "sha1":
3134
default:
3235
return crypto.createSign("RSA-SHA1");
3336
}

src/passport-saml/multiSamlStrategy.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414

1515
class MultiSamlStrategy extends SamlStrategy {
1616
_options: MultiSamlConfig;
17-
constructor(options: MultiSamlConfig, verify: VerifyWithRequest | VerifyWithoutRequest) {
17+
18+
constructor(options: MultiSamlConfig, verify: VerifyWithRequest);
19+
constructor(options: MultiSamlConfig, verify: VerifyWithoutRequest);
20+
constructor(options: MultiSamlConfig, verify: never) {
1821
if (!options || typeof options.getSamlOptions != "function") {
1922
throw new Error("Please provide a getSamlOptions function");
2023
}
@@ -33,7 +36,7 @@ class MultiSamlStrategy extends SamlStrategy {
3336
this._options = options;
3437
}
3538

36-
authenticate(req: RequestWithUser, options: AuthenticateOptions & AuthorizeOptions) {
39+
authenticate(req: RequestWithUser, options: AuthenticateOptions) {
3740
this._options.getSamlOptions(req, (err, samlOptions) => {
3841
if (err) {
3942
return this.error(err);

src/passport-saml/saml-post-signing.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SignedXml } from "xml-crypto";
22
import * as algorithms from "./algorithms";
3-
import { SAMLOptions } from "./types";
3+
import { SamlOptions, SamlSigningOptions } from "./types";
44

55
const authnRequestXPath =
66
'/*[local-name(.)="AuthnRequest" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:protocol"]';
@@ -11,11 +11,11 @@ const defaultTransforms = [
1111
"http://www.w3.org/2001/10/xml-exc-c14n#",
1212
];
1313

14-
export function signSamlPost(samlMessage: string, xpath: string, options: SAMLOptions) {
14+
export function signSamlPost(samlMessage: string, xpath: string, options: SamlSigningOptions) {
1515
if (!samlMessage) throw new Error("samlMessage is required");
1616
if (!xpath) throw new Error("xpath is required");
1717
if (!options) {
18-
options = {} as SAMLOptions;
18+
options = {} as SamlSigningOptions;
1919
}
2020

2121
if (options.privateCert) {
@@ -41,6 +41,6 @@ export function signSamlPost(samlMessage: string, xpath: string, options: SAMLOp
4141
return sig.getSignedXml();
4242
}
4343

44-
export function signAuthnRequestPost(authnRequest: string, options: SAMLOptions) {
44+
export function signAuthnRequestPost(authnRequest: string, options: SamlSigningOptions) {
4545
return signSamlPost(authnRequest, authnRequestXPath, options);
4646
}

0 commit comments

Comments
 (0)