Skip to content

Commit

Permalink
chore: update sentinel integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Benmuiruri committed Dec 2, 2024
1 parent 3a5fd7c commit f3690ad
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
12 changes: 6 additions & 6 deletions tests/integration/api/server.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,13 @@ describe('server', () => {
const haproxyRequests = haproxyLogs.filter(entry => getReqId(entry) === reqID);
expect(haproxyRequests.length).to.equal(13);
expect(haproxyRequests[0]).to.include('_session');
expect(haproxyRequests[5]).to.include('/medic-test/_design/medic/_view/contacts_by_depth');
expect(haproxyRequests[6]).to.include('/medic-test/_design/medic/_view/docs_by_replication_key');
expect(haproxyRequests[7]).to.include('/medic-test-purged-cache/purged-docs-');
expect(haproxyRequests[8]).to.include('/medic-test-purged-role-');
expect(haproxyRequests[9]).to.include('/medic-test-logs/replication-count-');
expect(haproxyRequests[6]).to.include('/medic-test/_design/medic/_view/contacts_by_depth');
expect(haproxyRequests[7]).to.include('/medic-test/_design/medic/_view/docs_by_replication_key');
expect(haproxyRequests[8]).to.include('/medic-test-purged-cache/purged-docs-');
expect(haproxyRequests[9]).to.include('/medic-test-purged-role-');
expect(haproxyRequests[10]).to.include('/medic-test-logs/replication-count-');
expect(haproxyRequests[11]).to.include('/medic-test/_all_docs');
expect(haproxyRequests[11]).to.include('/medic-test-logs/replication-count-');
expect(haproxyRequests[12]).to.include('/medic-test/_all_docs');
});

it('should propagate ID via couch requests', async () => {
Expand Down
1 change: 1 addition & 0 deletions tests/integration/sentinel/schedules/purging.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ describe('Server side purge', () => {
roles: ['district_admin', 'purge_regular'],
};
await updateUser(updatedUser2);
await utils.resetUserPassword([updatedUser2]);

responseDocsUser1 = await requestDocs('user1');
responseDocsUser2 = await requestDocs('user2');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const ORIGINAL_USER = utils.deepFreeze({
roles: ['chw'],
});

const newUsers = [];

const newPassword = 'Pa33word1';

const newUsers = [];

const getSettings = ({
transitions: { create_user_for_contacts = true } = {},
token_login: { enabled = true } = {},
Expand All @@ -45,13 +45,13 @@ const getSettings = ({
app_url,
});

const loginAsUser = (username) => {
const loginAsUser = ({ username, password }) => {
const opts = {
path: '/medic/login',
method: 'POST',
simple: false,
noAuth: true,
body: { user: username, password: newPassword },
body: { user: username, password },
followRedirect: false,
};
return utils.request(opts);
Expand Down Expand Up @@ -128,7 +128,7 @@ describe('create_user_for_contacts', () => {
await utils.resetUserPassword([ORIGINAL_USER]);
newUsers.push(ORIGINAL_USER.username);
// Can log in as user
assert.include(await loginAsUser(ORIGINAL_USER), { statusCode: 302 });
assert.include(await loginAsUser({ ...ORIGINAL_USER, password: newPassword }), { statusCode: 302 });
await utils.saveDoc(NEW_PERSON);
// Write another contact that has a user being created and another user being replaced
// (This is an approximation of behavior that could happen if Sentinel was down when the
Expand Down Expand Up @@ -222,7 +222,7 @@ describe('create_user_for_contacts', () => {
await utils.resetUserPassword([ORIGINAL_USER]);
newUsers.push(ORIGINAL_USER.username);
// Can log in as user
assert.include(await loginAsUser(ORIGINAL_USER), { statusCode: 302 });
assert.include(await loginAsUser({ ...ORIGINAL_USER, password: newPassword }), { statusCode: 302 });
await utils.saveDoc(NEW_PERSON);
const originalContact = await utils.getDoc(ORIGINAL_PERSON._id);
originalContact.user_for_contact = {
Expand All @@ -240,7 +240,7 @@ describe('create_user_for_contacts', () => {
// Transition successful
assert.isTrue(transitions.create_user_for_contacts.ok);
// Can no longer log in as user
assert.include(await loginAsUser(ORIGINAL_USER), { statusCode: 401 });
assert.include(await loginAsUser({ ...ORIGINAL_USER, password: newPassword }), { statusCode: 401 });
// User's password was automatically reset. Change it to something we know.
await updateUserPassword(ORIGINAL_USER.username, 'n3wPassword!');
// Can still login as original user with new password
Expand Down Expand Up @@ -280,7 +280,7 @@ describe('create_user_for_contacts', () => {
await utils.resetUserPassword([otherUser]);
newUsers.push(otherUser.username);
// Can log in as user
assert.include(await loginAsUser(ORIGINAL_USER), { statusCode: 302 });
assert.include(await loginAsUser({ ...ORIGINAL_USER, password: newPassword }), { statusCode: 302 });
await utils.saveDoc(NEW_PERSON);
const originalContact = await utils.getDoc(ORIGINAL_PERSON._id);
originalContact.user_for_contact = {
Expand Down Expand Up @@ -330,7 +330,7 @@ describe('create_user_for_contacts', () => {
const [otherUserSettings] = await utils.getUserSettings({ name: otherUser.username });
assert.equal(otherUserSettings.contact_id, ORIGINAL_PERSON._id);
// Can still log in as other user
assert.include(await loginAsUser(otherUser), { statusCode: 302 });
assert.include(await loginAsUser({ ...otherUser, password: newPassword }), { statusCode: 302 });
});

it('replaces multiple users for a contact', async () => {
Expand All @@ -342,7 +342,7 @@ describe('create_user_for_contacts', () => {
await utils.createUsers([otherUser]);
newUsers.push(otherUser.username);
// Can log in as users
assert.include(await loginAsUser(ORIGINAL_USER), { statusCode: 302 });
assert.include(await loginAsUser({ ...ORIGINAL_USER, password: newPassword }), { statusCode: 302 });
assert.include(await loginAsUser(otherUser), { statusCode: 302 });
await utils.saveDoc(NEW_PERSON);
const originalContact = await utils.getDoc(ORIGINAL_PERSON._id);
Expand Down

0 comments on commit f3690ad

Please sign in to comment.