Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbarth committed Feb 17, 2024
1 parent f1c13ac commit a67bedb
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"reporter": "spec",
"require": ["choma", "ts-node/register"],
"spec": "test/**/*.spec.ts",
"watch-files": "test/**/*.spec.ts"
"watch-files": "test/**/*.spec.ts",
"loader": "ts-node/esm"
}
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"prettier-plugin-packagejson": "^2.4.10",
"release-it": "^17.0.5",
"sinon": "^17.0.1",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
Expand All @@ -99,5 +100,6 @@
},
"publishConfig": {
"access": "public"
}
},
"type": "module"
}
4 changes: 2 additions & 2 deletions src/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as crypto from "crypto";
import { assertRequired } from "./utility";
import { PemLabel } from "./types";
import { assertRequired } from "./utility.js";
import { PemLabel } from "./types.js";
/**
* PEM format has wide range of usages, but this library
* is enforcing RFC7468 which focuses on PKIX, PKCS and CMS.
Expand Down
12 changes: 6 additions & 6 deletions src/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { stripPemHeaderAndFooter } from "./crypto";
import { stripPemHeaderAndFooter } from "./crypto.js";
import {
isValidSamlSigningOptions,
ServiceMetadataXML,
XMLObject,
GenerateServiceProviderMetadataParams,
} from "./types";
import { assertRequired, signXmlMetadata } from "./utility";
import { buildXmlBuilderObject } from "./xml";
import { generateUniqueId as generateUniqueIdDefault } from "./crypto";
import { DEFAULT_IDENTIFIER_FORMAT, DEFAULT_WANT_ASSERTIONS_SIGNED } from "./constants";
} from "./types.js";
import { assertRequired, signXmlMetadata } from "./utility.js";
import { buildXmlBuilderObject } from "./xml.js";
import { generateUniqueId as generateUniqueIdDefault } from "./crypto.js";
import { DEFAULT_IDENTIFIER_FORMAT, DEFAULT_WANT_ASSERTIONS_SIGNED } from "./constants.js";

export const generateServiceProviderMetadata = (
params: GenerateServiceProviderMetadataParams,
Expand Down
4 changes: 2 additions & 2 deletions src/saml-post-signing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SamlSigningOptions } from "./types";
import { signXml } from "./xml";
import { SamlSigningOptions } from "./types.js";
import { signXml } from "./xml.js";

const authnRequestXPath =
'/*[local-name(.)="AuthnRequest" and namespace-uri(.)="urn:oasis:names:tc:SAML:2.0:protocol"]';
Expand Down
20 changes: 10 additions & 10 deletions src/saml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import * as crypto from "crypto";
import { URL } from "url";
import * as querystring from "querystring";
import * as util from "util";
import { InMemoryCacheProvider } from "./in-memory-cache-provider";
import * as algorithms from "./algorithms";
import { InMemoryCacheProvider } from "./in-memory-cache-provider.js";
import * as algorithms from "./algorithms.js";
import { ParsedQs } from "qs";
import {
isValidSamlSigningOptions,
Expand All @@ -27,8 +27,8 @@ import {
XMLValue,
SamlResponseXmlJs,
AuthOptions,
} from "./types";
import { assertBooleanIfPresent, assertRequired } from "./utility";
} from "./types.js";
import { assertBooleanIfPresent, assertRequired } from "./utility.js";
import {
buildXml2JsObject,
buildXmlBuilderObject,
Expand All @@ -38,12 +38,12 @@ import {
parseXml2JsFromString,
validateSignature,
xpath,
} from "./xml";
import { keyInfoToPem, generateUniqueId } from "./crypto";
import { dateStringToTimestamp, generateInstant } from "./date-time";
import { signAuthnRequestPost } from "./saml-post-signing";
import { generateServiceProviderMetadata } from "./metadata";
import { DEFAULT_IDENTIFIER_FORMAT, DEFAULT_WANT_ASSERTIONS_SIGNED } from "./constants";
} from "./xml.js";
import { keyInfoToPem, generateUniqueId } from "./crypto.js";
import { dateStringToTimestamp, generateInstant } from "./date-time.js";
import { signAuthnRequestPost } from "./saml-post-signing.js";
import { generateServiceProviderMetadata } from "./metadata.js";
import { DEFAULT_IDENTIFIER_FORMAT, DEFAULT_WANT_ASSERTIONS_SIGNED } from "./constants.js";

const debug = Debug("node-saml");
const inflateRawAsync = util.promisify(zlib.inflateRaw);
Expand Down
4 changes: 2 additions & 2 deletions src/utility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SamlSigningOptions } from "./types";
import { signXml } from "./xml";
import { SamlSigningOptions } from "./types.js";
import { signXml } from "./xml.js";

export function assertRequired<T>(value: T | null | undefined, error?: string): asserts value {
if (value === undefined || value === null || (typeof value === "string" && value.length === 0)) {
Expand Down
6 changes: 3 additions & 3 deletions src/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
XmlJsObject,
XMLOutput,
XmlSignatureLocation,
} from "./types";
import * as algorithms from "./algorithms";
import { assertRequired } from "./utility";
} from "./types.js";
import * as algorithms from "./algorithms.js";
import { assertRequired } from "./utility.js";
import * as isDomNode from "@xmldom/is-dom-node";
import Debug from "debug";

Expand Down
6 changes: 3 additions & 3 deletions test/cache.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";
import * as sinon from "sinon";
import { SAML } from "../src/saml";
import { SamlConfig, ValidateInResponseTo } from "../src/types";
import { FAKE_CERT } from "./types";
import { SAML } from "../src/saml.js";
import { SamlConfig, ValidateInResponseTo } from "../src/types.js";
import { FAKE_CERT } from "./types.js";

describe("Cache tests /", () => {
let fakeClock: sinon.SinonFakeTimers;
Expand Down
4 changes: 2 additions & 2 deletions test/crypto.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as fs from "fs";
import { expect } from "chai";
import { keyInfoToPem, generateUniqueId, stripPemHeaderAndFooter } from "../src/crypto";
import { keyInfoToPem, generateUniqueId, stripPemHeaderAndFooter } from "../src/crypto.js";
import {
TEST_CERT_SINGLELINE,
TEST_CERT_MULTILINE,
TEST_PUBLIC_KEY_SINGLELINE,
TEST_PUBLIC_KEY_MULTILINE,
} from "./types";
} from "./types.js";

describe("crypto.ts", function () {
describe("generateUniqueID", function () {
Expand Down
11 changes: 8 additions & 3 deletions test/saml-post-signing-tests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as fs from "fs";
import { signSamlPost, signAuthnRequestPost } from "../src/saml-post-signing";
import { SamlSigningOptions } from "../src/types";
import { parseXml2JsFromString } from "../src/xml";
import { signSamlPost, signAuthnRequestPost } from "../src/saml-post-signing.js";
import { SamlSigningOptions } from "../src/types.js";
import { parseXml2JsFromString } from "../src/xml.js";
import { expect } from "chai";
import path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const signingKey = fs.readFileSync(__dirname + "/static/key.pem");

Expand Down
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2018" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["es2018"] /* Specify library files to be included in the compilation. */,
"target": "ES2020" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "ESNext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["ES2020"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down Expand Up @@ -41,7 +41,7 @@
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "typeRoots": [], /* List of folders to include type definitions from. */
Expand Down

0 comments on commit a67bedb

Please sign in to comment.