Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fredriklindberg committed Jan 25, 2024
1 parent 7553bd7 commit 5ff5d96
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 33 deletions.
2 changes: 1 addition & 1 deletion test/system/storage/test_pgsql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ describe('pgsql storage', () => {
const sqliteStorage = StorageManager.getStorage() as PgsqlStorageProvider;
const expiry: number = sqliteStorage["expiryCleanInterval"];

await clock.tickAsync(expiry * 1000);
await clock.tickAsync(expiry * 2);

const db = new Pgsql.Client({connectionString: PGSQL_URL });
await db.connect();
Expand Down
2 changes: 1 addition & 1 deletion test/system/storage/test_sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ describe('sqlite storage', () => {
const sqliteStorage = StorageManager.getStorage() as SqliteStorageProvider;
const expiry: number = sqliteStorage["expiryCleanInterval"];

await clock.tickAsync(expiry * 1000);
await clock.tickAsync(expiry * 2);

const db = new Sqlite(sqlitedb, { readonly: true });
const stm = db.prepare(`SELECT key FROM test WHERE key = ?`);
Expand Down
2 changes: 2 additions & 0 deletions test/unit/account/test_account-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('account service', () => {
it(`can create account`, async () => {
const account = await accountService.create();
assert(account instanceof Account);
assert(account.id != undefined);
assert(account.created_at != undefined);
assert(account.created_at == account.updated_at);

Expand Down Expand Up @@ -214,6 +215,7 @@ describe('account service', () => {
await accountService.disable(account.id, true, "spam");

account = await accountService.get(account.id);
assert(account?.id != undefined);
assert(account?.status.disabled == true);
assert(account?.status.disabled_at != undefined);
assert(account?.status.disabled_reason == "spam");
Expand Down
45 changes: 43 additions & 2 deletions test/unit/ingress/test_http_ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ describe('http ingress', () => {
account = await accountService.create();
assert(account != undefined);
const tunnelId = crypto.randomBytes(20).toString('hex');
tunnel = await tunnelService.create(tunnelId, account.id);
tunnel = await tunnelService.update(tunnel.id, account.id, (tunnel) => {
tunnel = await tunnelService.create(tunnelId, <string>account.id);
tunnel = await tunnelService.update(tunnelId, <string>account.id, (tunnel) => {
tunnel.ingress.http.enabled = true;
});

Expand Down Expand Up @@ -121,6 +121,8 @@ describe('http ingress', () => {
const connectTunnel = async (): Promise<void> => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

let res = await tunnelService.connect(tunnel.id, account.id, transport, {peer: "127.0.0.1"});
assert(res == true, "failed to connect tunnel");
Expand All @@ -137,6 +139,8 @@ describe('http ingress', () => {
it('can send traffic', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

client.on('connection', (sock: Duplex) => {
const targetSock = new net.Socket();
Expand Down Expand Up @@ -206,6 +210,8 @@ describe('http ingress', () => {
it('agent does not timeout during transfer', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

let res = await tunnelService.connect(tunnel.id, account.id, transport, {peer: "127.0.0.1"});
assert(res == true, "failed to connect tunnel");
Expand Down Expand Up @@ -259,6 +265,8 @@ describe('http ingress', () => {
it('agent timeout on idle', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down Expand Up @@ -288,6 +296,8 @@ describe('http ingress', () => {
it(`http ingress can handle websocket upgrades`, async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

client.on('connection', (sock: Duplex) => {
const targetSock = new net.Socket();
Expand Down Expand Up @@ -358,6 +368,8 @@ describe('http ingress', () => {
it('handles ingress altname', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

sinon.stub(dns, 'resolveCname')
.withArgs('custom-name.example')
Expand All @@ -369,6 +381,9 @@ describe('http ingress', () => {
]
});

assert(tunnel instanceof Tunnel);
assert(tunnel.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();

Expand All @@ -392,6 +407,8 @@ describe('http ingress', () => {
it('adding altname without cname throws error', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

let error: CustomError | undefined;
try {
Expand All @@ -411,6 +428,8 @@ describe('http ingress', () => {
it('adding altname with wrong cname throws error', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

sinon.stub(dns, 'resolveCname')
.withArgs('custom-name.example')
Expand All @@ -436,10 +455,14 @@ describe('http ingress', () => {
it('request headers are rewritten with the target host for http', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

tunnel = await tunnelService.update(tunnel.id, account?.id, (config) => {
config.target.url = "https://echo.localhost.example"
});
assert(tunnel instanceof Tunnel);
assert(tunnel.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down Expand Up @@ -470,10 +493,14 @@ describe('http ingress', () => {
it('request headers are not rewritten with the target host for non-http', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

tunnel = await tunnelService.update(tunnel.id, account?.id, (config) => {
config.target.url = "tcps://echo.localhost.example"
});
assert(tunnel instanceof Tunnel);
assert(tunnel.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down Expand Up @@ -504,6 +531,8 @@ describe('http ingress', () => {
it('forwarded headers are added to request', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down Expand Up @@ -537,6 +566,8 @@ describe('http ingress', () => {
it('x-forwarded headers from request are read', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down Expand Up @@ -571,6 +602,8 @@ describe('http ingress', () => {
it('exposr via header is added to request', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand All @@ -594,6 +627,8 @@ describe('http ingress', () => {
it('request loops returns 508', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

forwardTo("localhost", 10000);
await connectTunnel();
Expand All @@ -616,6 +651,8 @@ describe('http ingress', () => {
it('un-responsive target returns 502', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

forwardTo("localhost", 20001);
await connectTunnel();
Expand Down Expand Up @@ -672,10 +709,14 @@ describe('http ingress', () => {
it('disabled ingress returns 403', async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

tunnel = await tunnelService.update(tunnel.id, account?.id, (config) => {
config.ingress.http.enabled = false;
});
assert(tunnel instanceof Tunnel);
assert(tunnel.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down
18 changes: 16 additions & 2 deletions test/unit/ingress/test_sni-ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ describe('sni', () => {

account = await accountService.create();
assert(account != undefined);
assert(account.id != undefined);

const tunnelId = 'test';
tunnel = await tunnelService.create(tunnelId, account.id);
assert(tunnel instanceof Tunnel);
assert(tunnel.id == tunnelId);

tunnel = await tunnelService.update(tunnel.id, account.id, (tunnel) => {
tunnel.ingress.sni.enabled = true;
});
assert(tunnel instanceof Tunnel);
assert(tunnel.id == tunnelId);

const url = IngressManager.getIngress(IngressType.INGRESS_SNI).getBaseUrl(tunnel.id);

Expand Down Expand Up @@ -183,8 +189,8 @@ describe('sni', () => {
account = await accountService.create();
assert(account != undefined);
const tunnelId = crypto.randomBytes(20).toString('hex');
tunnel = await tunnelService.create(tunnelId, account.id);
tunnel = await tunnelService.update(tunnel.id, account.id, (tunnel) => {
tunnel = await tunnelService.create(tunnelId, <string>account.id);
tunnel = await tunnelService.update(tunnelId, <string>account.id, (tunnel) => {
tunnel.ingress.sni.enabled = true;
});

Expand All @@ -206,6 +212,8 @@ describe('sni', () => {
const connectTunnel = async (): Promise<void> => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

let res = await tunnelService.connect(tunnel.id, account.id, transport, {peer: "127.0.0.1"});
assert(res == true, "failed to connect tunnel");
Expand Down Expand Up @@ -251,6 +259,8 @@ describe('sni', () => {
it(`can send traffic`, async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down Expand Up @@ -304,12 +314,16 @@ describe('sni', () => {
it(`tls handshake fails for disabled ingress`, async () => {
assert(tunnel != undefined);
assert(account != undefined);
assert(tunnel.id != undefined);
assert(account.id != undefined);

const url = new URL(`${tunnel.config.ingress.sni.url}`);

tunnel = await tunnelService.update(tunnel.id, account?.id, (config) => {
config.ingress.sni.enabled = false;
});
assert(tunnel instanceof Tunnel);
assert(tunnel.id != undefined)

forwardTo("localhost", 20000);
await connectTunnel();
Expand Down
19 changes: 11 additions & 8 deletions test/unit/transport/test_ssh_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ describe('SSH transport', () => {

echoServer = await createEchoHttpServer();

account = <any>await accountService.create();
const createdAccount = await accountService.create();
assert(createdAccount instanceof Account)
assert(createdAccount.id != undefined);
account = createdAccount
tunnelId = crypto.randomBytes(20).toString('hex');
tunnel = await tunnelService.create(tunnelId, account.id);
tunnel = await tunnelService.create(tunnelId, <string>account.id);
});

afterEach(async () => {
Expand Down Expand Up @@ -91,7 +94,7 @@ describe('SSH transport', () => {
}
});

tunnel = await tunnelService.update(tunnelId, account.id, (tunnelConfig) => {
tunnel = await tunnelService.update(tunnelId, <string>account.id, (tunnelConfig) => {
tunnelConfig.transport.ssh.enabled = true;
tunnelConfig.ingress.http.enabled = true;
});
Expand Down Expand Up @@ -211,7 +214,7 @@ describe('SSH transport', () => {
}
});

tunnel = await tunnelService.update(tunnelId, account.id, (tunnelConfig) => {
tunnel = await tunnelService.update(tunnelId, <string>account.id, (tunnelConfig) => {
tunnelConfig.transport.ssh.enabled = true;
tunnelConfig.ingress.http.enabled = true;
});
Expand Down Expand Up @@ -375,16 +378,16 @@ describe('SSH transport', () => {
}
});

tunnel = await tunnelService.update(tunnelId, account.id, (tunnelConfig) => {
tunnel = await tunnelService.update(tunnelId, <string>account.id, (tunnelConfig) => {
tunnelConfig.transport.ssh.enabled = true;
tunnelConfig.ingress.http.enabled = true;
tunnelConfig.target.url = "http://localhost:20000";
});

const tunnelId2 = crypto.randomBytes(20).toString('hex');
let tunnel2 = await tunnelService.create(tunnelId2, account.id);
let tunnel2 = await tunnelService.create(tunnelId2, <string>account.id);

tunnel2 = await tunnelService.update(tunnelId2, account.id, (tunnelConfig) => {
tunnel2 = await tunnelService.update(tunnelId2, <string>account.id, (tunnelConfig) => {
tunnelConfig.transport.ssh.enabled = true;
tunnelConfig.ingress.http.enabled = true;
});
Expand Down Expand Up @@ -486,7 +489,7 @@ describe('SSH transport', () => {
}
});

tunnel = await tunnelService.update(tunnelId, account.id, (tunnelConfig) => {
tunnel = await tunnelService.update(tunnelId, <string>account.id, (tunnelConfig) => {
tunnelConfig.transport.ssh.enabled = true;
tunnelConfig.ingress.http.enabled = true;
tunnelConfig.target.url = "https://localhost:20001";
Expand Down
9 changes: 6 additions & 3 deletions test/unit/transport/test_ws_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ describe('WS transport', () => {

echoServer = await createEchoHttpServer();

account = <any>await accountService.create();
const createdAccount = await accountService.create();
assert(createdAccount instanceof Account, "did not create account");
assert(createdAccount.id != undefined, "account id is undefined");
account = createdAccount
tunnelId = crypto.randomBytes(20).toString('hex');
tunnel = await tunnelService.create(tunnelId, account.id);
tunnel = await tunnelService.create(tunnelId, <string>account.id);
});

afterEach(async () => {
Expand Down Expand Up @@ -94,7 +97,7 @@ describe('WS transport', () => {
}
});

tunnel = await tunnelService.update(tunnelId, account.id, (tunnelConfig) => {
tunnel = await tunnelService.update(tunnelId, <string>account.id, (tunnelConfig) => {
tunnelConfig.transport.ws.enabled = true;
tunnelConfig.ingress.http.enabled = true;
});
Expand Down
Loading

0 comments on commit 5ff5d96

Please sign in to comment.