Skip to content

Commit

Permalink
Satrt test app
Browse files Browse the repository at this point in the history
  • Loading branch information
psrpinto committed Sep 19, 2023
1 parent 7a95147 commit ba955d6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
3 changes: 3 additions & 0 deletions integration-tests/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ ISSUER_URL="https://localhost:8443"
CLIENT_ID="wqh8Znfbd2yfEfJzavxFcMcZYEYdCuEm"
CLIENT_SECRET="bdouoZ9Fe9KimG8eqNyx9VjMoAceP34h"
TLS_CA_CERT="../../matrix-oidc-playground/tls/ca/rootCA.pem"
TLS_CERT="../../matrix-oidc-playground/tls/tls.pem"
TLS_KEY="../../matrix-oidc-playground/tls/tls-key.pem"
APP_BASE_URL="https://localhost:7443"
3 changes: 3 additions & 0 deletions integration-tests/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ declare global {
CLIENT_ID: string,
CLIENT_SECRET: string,
TLS_CA_CERT: string,
TLS_CERT: string,
TLS_KEY: string,
APP_BASE_URL: string,
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion integration-tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as dotenv from "dotenv"
import * as fs from "fs";
import path from "node:path";
import {OpenIdClient} from "./src/OpenIdClient";
import {App} from "./src/App";

dotenv.config({ path: ".env" });
if (fs.existsSync(".env.local")) {
Expand All @@ -10,7 +11,7 @@ if (fs.existsSync(".env.local")) {

async function run() {
const env = process.env;
if (!env.ISSUER_URL || !env.CLIENT_ID || !env.CLIENT_SECRET || !env.TLS_CA_CERT) {
if (!env.ISSUER_URL || !env.CLIENT_ID || !env.CLIENT_SECRET || !env.TLS_CA_CERT || !env.TLS_CERT || !env.TLS_KEY || !env.APP_BASE_URL) {
console.error("Some or all required environment variables were not defined. Set them in the .env file.");
process.exit(1);
}
Expand All @@ -25,6 +26,13 @@ async function run() {

const authorizationUrl = await client.authorizationUrl();
console.debug(`Got authorization URL: ${authorizationUrl}`);

const app = new App({
baseUrl: env.APP_BASE_URL,
tlsCertAbsolutePath: path.resolve(env.TLS_CERT),
tlsKeyAbsolutePath: path.resolve(env.TLS_KEY),
})
app.start();
}

void run();
33 changes: 33 additions & 0 deletions integration-tests/src/App.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as https from "https";
import fs from "fs";
import {Server} from "node:https";
import * as http from "http";

type Options = {
baseUrl: string,
tlsCertAbsolutePath: string,
tlsKeyAbsolutePath: string,
};

export class App {
private readonly server: Server<typeof http.IncomingMessage, typeof http.ServerResponse>;

constructor(private readonly options: Options) {
this.server = https.createServer({
key: fs.readFileSync(options.tlsKeyAbsolutePath, "utf8"),
cert: fs.readFileSync(options.tlsCertAbsolutePath, "utf8"),
}, (req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
}

start() {
const baseUrl = new URL(this.options.baseUrl);
// @ts-ignore
this.server.listen(baseUrl.port, baseUrl.hostname, () => {
console.info(`App listening at ${baseUrl}`);
});
}
}

0 comments on commit ba955d6

Please sign in to comment.