Deflake more tests
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -9,11 +9,11 @@ Please see LICENSE files in the repository root for full details.
|
||||
import { Fixtures } from "@playwright/test";
|
||||
import { TestContainers } from "testcontainers";
|
||||
|
||||
import { Services } from "../../../services.ts";
|
||||
import { Services, TestFixtures } from "../../../services.ts";
|
||||
import { OAuthServer } from "../../oauth_server";
|
||||
|
||||
export const legacyOAuthHomeserver: Fixtures<{}, Services> = {
|
||||
_homeserver: [
|
||||
export const legacyOAuthHomeserver: Fixtures<TestFixtures, Services, TestFixtures> = {
|
||||
_oAuthServer: [
|
||||
async ({ _homeserver: container }, use) => {
|
||||
const server = new OAuthServer();
|
||||
const port = server.start();
|
||||
@@ -43,9 +43,13 @@ export const legacyOAuthHomeserver: Fixtures<{}, Services> = {
|
||||
},
|
||||
],
|
||||
});
|
||||
await use(container);
|
||||
await use(server);
|
||||
server.stop();
|
||||
},
|
||||
{ scope: "worker" },
|
||||
],
|
||||
oAuthServer: async ({ _oAuthServer }, use, testInfo) => {
|
||||
_oAuthServer.onTestStarted(testInfo);
|
||||
await use(_oAuthServer);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -9,12 +9,21 @@ Please see LICENSE files in the repository root for full details.
|
||||
import http from "http";
|
||||
import express from "express";
|
||||
import { AddressInfo } from "net";
|
||||
import { TestInfo } from "@playwright/test";
|
||||
|
||||
import { randB64Bytes } from "../utils/rand.ts";
|
||||
|
||||
export class OAuthServer {
|
||||
private server?: http.Server;
|
||||
private sub?: string;
|
||||
|
||||
public onTestStarted(testInfo: TestInfo): void {
|
||||
this.sub = testInfo.testId;
|
||||
}
|
||||
|
||||
public start(): number {
|
||||
if (this.server) this.stop();
|
||||
const token = randB64Bytes(16);
|
||||
|
||||
const app = express();
|
||||
|
||||
@@ -28,7 +37,7 @@ export class OAuthServer {
|
||||
const code = req.body.code;
|
||||
if (code === "valid_auth_code") {
|
||||
res.send({
|
||||
access_token: "oauth_access_token",
|
||||
access_token: token,
|
||||
token_type: "Bearer",
|
||||
expires_in: "3600",
|
||||
});
|
||||
@@ -43,7 +52,7 @@ export class OAuthServer {
|
||||
|
||||
// return an OAuth2 user info object
|
||||
res.send({
|
||||
sub: "alice",
|
||||
sub: this.sub,
|
||||
name: "Alice",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user