diff --git a/config.test.json b/config.test.json index ba3b75b..27a8298 100644 --- a/config.test.json +++ b/config.test.json @@ -4,7 +4,7 @@ "api": { "listenHost": "127.0.0.1", "listenPort": "50080", - "proxy": false, + "proxy": true, "corsAllowedOrigins": [ "https://reservation.snucse.org" ] diff --git a/test/api/login.test.ts b/test/api/login.test.ts index 80ca734..4e5adac 100644 --- a/test/api/login.test.ts +++ b/test/api/login.test.ts @@ -47,7 +47,7 @@ test('test login with credential', async t => { }); }); -test.serial('test PAM login with credential and host', async t => { +test('test PAM login with credential and host', async t => { let username = ''; let password = ''; let userIdx = -1; @@ -69,8 +69,8 @@ test.serial('test PAM login with credential and host', async t => { groupIdx = await model.groups.create(tr, trans, trans, uuid()); await model.users.addUserMembership(tr, userIdx, groupIdx); - hostIdx = await model.hosts.addHost(tr, 'test', '127.0.0.1'); - hostGroupIdx = await model.hosts.addHostGroup(tr, 'test group'); + hostIdx = await model.hosts.addHost(tr, 'login-test-0', '10.0.1.0'); + hostGroupIdx = await model.hosts.addHostGroup(tr, 'test group 0'); await model.hosts.addHostToGroup(tr, hostIdx, hostGroupIdx); permissionIdx = await model.permissions.create(tr, trans, trans); @@ -79,7 +79,9 @@ test.serial('test PAM login with credential and host', async t => { tr.ensureHasAccessExclusiveLock('hosts'); }, ['users', 'group_reachable_cache', 'hosts']); - const agent = request.agent(app); + const agent = request.agent(app) + .set('x-forwarded-for', '10.0.1.0') + .set('forwarded', 'for=10.0.1.0'); let response; @@ -110,12 +112,12 @@ test.serial('test PAM login with credential and host', async t => { // Cleanup await model.pgDo(async tr => { - await tr.query('DELETE FROM hosts WHERE name = $1', ['test']); - await tr.query('DELETE FROM host_groups WHERE name = $1', ['test group']); + await tr.query('DELETE FROM hosts WHERE name = $1', ['login-test-0']); + await tr.query('DELETE FROM host_groups WHERE name = $1', ['test group 0']); }); }); -test.serial('test PAM login with credential and pubkey', async t => { +test('test PAM login with credential and pubkey', async t => { let username = ''; let password = ''; let userIdx = -1; @@ -140,8 +142,8 @@ test.serial('test PAM login with credential and pubkey', async t => { groupIdx = await model.groups.create(tr, trans, trans, uuid()); await model.users.addUserMembership(tr, userIdx, groupIdx); - hostIdx = await model.hosts.addHost(tr, 'test', '127.0.0.1', publicKey); - hostGroupIdx = await model.hosts.addHostGroup(tr, 'test group'); + hostIdx = await model.hosts.addHost(tr, 'login-test-1', '10.0.1.1', publicKey); + hostGroupIdx = await model.hosts.addHostGroup(tr, 'test group 1'); await model.hosts.addHostToGroup(tr, hostIdx, hostGroupIdx); permissionIdx = await model.permissions.create(tr, trans, trans); @@ -150,7 +152,9 @@ test.serial('test PAM login with credential and pubkey', async t => { tr.ensureHasAccessExclusiveLock('hosts'); }, ['users', 'group_reachable_cache', 'hosts']); - const agent = request.agent(app); + const agent = request.agent(app) + .set('x-forwarded-for', '10.0.1.1') + .set('forwarded', 'for=10.0.1.1'); let response; @@ -230,8 +234,8 @@ test.serial('test PAM login with credential and pubkey', async t => { // Cleanup await model.pgDo(async tr => { - await tr.query('DELETE FROM hosts WHERE name = $1', ['test']); - await tr.query('DELETE FROM host_groups WHERE name = $1', ['test group']); + await tr.query('DELETE FROM hosts WHERE name = $1', ['login-test-1']); + await tr.query('DELETE FROM host_groups WHERE name = $1', ['test group 1']); }); }); diff --git a/test/api/nss.test.ts b/test/api/nss.test.ts index fe77155..18fdfad 100644 --- a/test/api/nss.test.ts +++ b/test/api/nss.test.ts @@ -3,8 +3,10 @@ import * as request from 'supertest'; import { app, config, model } from '../_setup'; import { createUser } from '../_test_utils'; -test.serial('fetch passwd entries', async t => { - const agent = request.agent(app); +test('fetch passwd entries', async t => { + const agent = request.agent(app) + .set('x-forwarded-for', '10.0.2.0') + .set('forwarded', 'for=10.0.2.0'); const expect = await model.pgDo(async tr => { const userIdx = await createUser(tr, model); @@ -23,7 +25,7 @@ test.serial('fetch passwd entries', async t => { // With host await model.pgDo(async tr => { - await model.hosts.addHost(tr, 'test', '127.0.0.1'); + await model.hosts.addHost(tr, 'nss-test-0', '10.0.2.0'); tr.ensureHasAccessExclusiveLock('hosts'); }, ['hosts']); @@ -32,13 +34,15 @@ test.serial('fetch passwd entries', async t => { t.true(response.text.includes(expect)); await model.pgDo(async tr => { - await tr.query('DELETE FROM hosts WHERE name = $1', ['test']); + await tr.query('DELETE FROM hosts WHERE name = $1', ['nss-test-0']); tr.ensureHasAccessExclusiveLock('hosts'); }, ['hosts']); }); -test.serial('fetch group entries', async t => { - const agent = request.agent(app); +test('fetch group entries', async t => { + const agent = request.agent(app) + .set('x-forwarded-for', '10.0.2.1') + .set('forwarded', 'for=10.0.2.1'); let username = ''; let expect = ''; @@ -59,7 +63,7 @@ test.serial('fetch group entries', async t => { // With host await model.pgDo(async tr => { - await model.hosts.addHost(tr, 'test', '127.0.0.1'); + await model.hosts.addHost(tr, 'nss-test-1', '10.0.2.1'); tr.ensureHasAccessExclusiveLock('hosts'); }, ['hosts']); @@ -69,16 +73,18 @@ test.serial('fetch group entries', async t => { t.true(response.text.split(':')[3].includes(username)); await model.pgDo(async tr => { - await tr.query('DELETE FROM hosts WHERE name = $1', ['test']); + await tr.query('DELETE FROM hosts WHERE name = $1', ['nss-test-1']); tr.ensureHasAccessExclusiveLock('hosts'); }, ['hosts']); }); -test.serial('test not-modified posix entries', async t => { - const agent = request.agent(app); +test('test not-modified posix entries', async t => { + const agent = request.agent(app) + .set('x-forwarded-for', '10.0.2.2') + .set('forwarded', 'for=10.0.2.2'); await model.pgDo(async tr => { - await model.hosts.addHost(tr, 'test', '127.0.0.1'); + await model.hosts.addHost(tr, 'nss-test-2', '10.0.2.2'); tr.ensureHasAccessExclusiveLock('hosts'); }, ['hosts']); @@ -100,7 +106,7 @@ test.serial('test not-modified posix entries', async t => { t.is(response.status, 304); await model.pgDo(async tr => { - await tr.query('DELETE FROM hosts WHERE name = $1', ['test']); + await tr.query('DELETE FROM hosts WHERE name = $1', ['nss-test-2']); tr.ensureHasAccessExclusiveLock('hosts'); }, ['hosts']); });