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 1c1bf0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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
25 changes: 23 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,6 +455,8 @@ 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"
Expand Down

0 comments on commit 1c1bf0d

Please sign in to comment.