Skip to content

Commit

Permalink
host 테스트의 레이스 컨디션 해결 시도
Browse files Browse the repository at this point in the history
  • Loading branch information
tirr-c committed Mar 23, 2024
1 parent c2d4ef7 commit f1c3088
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion config.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"api": {
"listenHost": "127.0.0.1",
"listenPort": "50080",
"proxy": false,
"proxy": true,
"corsAllowedOrigins": [
"https://reservation.snucse.org"
]
Expand Down
28 changes: 16 additions & 12 deletions test/api/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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']);
});
});

Expand Down
30 changes: 18 additions & 12 deletions test/api/nss.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']);

Expand All @@ -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 = '';
Expand All @@ -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']);

Expand All @@ -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']);

Expand All @@ -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']);
});

0 comments on commit f1c3088

Please sign in to comment.