From e083df64e461dd83938de024033c9f9a2766c7bd Mon Sep 17 00:00:00 2001 From: Randi Miller Date: Sun, 17 Mar 2019 04:00:50 -0400 Subject: [PATCH 1/4] fixes #11047 Switches Hall query to use lowercase name --- .../hall/GET-hall_heroes_heroId.test.js | 14 +++++++++++++- .../api-integration/v3/object-generators.js | 4 ++-- website/server/controllers/api-v3/hall.js | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js b/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js index b2d7bc6383..390f92514a 100644 --- a/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js +++ b/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js @@ -54,7 +54,7 @@ describe('GET /heroes/:heroId', () => { expect(heroRes.profile).to.have.all.keys(['name']); }); - it('returns only necessary hero data given username', async () => { + it('returns only necessary hero data given username with display case', async () => { let hero = await generateUser({ contributor: {tier: 23}, }); @@ -67,4 +67,16 @@ describe('GET /heroes/:heroId', () => { expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']); expect(heroRes.profile).to.have.all.keys(['name']); }); + + it('returns hero data given username without case sensitivity', async () => { + let hero = await generateUser({}, 'TestUpperCaseName123'); + let heroRes = await user.get(`/hall/heroes/${hero.auth.local.username.toLowerCase()}`); + + expect(heroRes).to.have.all.keys([ + '_id', 'id', 'balance', 'profile', 'purchased', + 'contributor', 'auth', 'items', + ]); + expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']); + expect(heroRes.profile).to.have.all.keys(['name']); + }); }); diff --git a/test/helpers/api-integration/v3/object-generators.js b/test/helpers/api-integration/v3/object-generators.js index 4e177ace00..19486dc39a 100644 --- a/test/helpers/api-integration/v3/object-generators.js +++ b/test/helpers/api-integration/v3/object-generators.js @@ -13,8 +13,8 @@ import * as Tasks from '../../../../website/server/models/task'; // parameter, such as the number of wolf eggs the user has, // , you can do so by passing in the full path as a string: // { 'items.eggs.Wolf': 10 } -export async function generateUser (update = {}) { - let username = (Date.now() + generateUUID()).substring(0, 20); +export async function generateUser (update = {}, manualUsername = null) { + let username = manualUsername || (Date.now() + generateUUID()).substring(0, 20); let password = 'password'; let email = `${username}@example.com`; diff --git a/website/server/controllers/api-v3/hall.js b/website/server/controllers/api-v3/hall.js index d3715bfda6..2073962af0 100644 --- a/website/server/controllers/api-v3/hall.js +++ b/website/server/controllers/api-v3/hall.js @@ -175,7 +175,7 @@ api.getHero = { if (validator.isUUID(heroId)) { query = {_id: heroId}; } else { - query = {'auth.local.username': heroId}; + query = {'auth.local.lowerCaseUsername': heroId.toLowerCase()}; } const hero = await User From e277a088ee7fd8bacaaed2e49a6faeda0f3873f7 Mon Sep 17 00:00:00 2001 From: Randi Miller Date: Sun, 17 Mar 2019 04:20:21 -0400 Subject: [PATCH 2/4] Added some additional comments --- test/helpers/api-integration/v3/object-generators.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/helpers/api-integration/v3/object-generators.js b/test/helpers/api-integration/v3/object-generators.js index 19486dc39a..00ef85a955 100644 --- a/test/helpers/api-integration/v3/object-generators.js +++ b/test/helpers/api-integration/v3/object-generators.js @@ -13,6 +13,11 @@ import * as Tasks from '../../../../website/server/models/task'; // parameter, such as the number of wolf eggs the user has, // , you can do so by passing in the full path as a string: // { 'items.eggs.Wolf': 10 } +// +// To manually set a username pass it as the second parameter. +// If no password is passed or it is falsy then a username will +// be auto-generated. +// Example: generateUser({}, 'TestName') adds user with the 'TestName' username. export async function generateUser (update = {}, manualUsername = null) { let username = manualUsername || (Date.now() + generateUUID()).substring(0, 20); let password = 'password'; From e644ae83fd3267e37fc99e6c3c2dcab068149af4 Mon Sep 17 00:00:00 2001 From: Randi Miller Date: Fri, 22 Mar 2019 14:44:27 -0400 Subject: [PATCH 3/4] Overrides for generateUser and test adjustment --- .../hall/GET-hall_heroes_heroId.test.js | 16 +++++----------- .../api-integration/v3/object-generators.js | 17 +++++++++-------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js b/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js index 390f92514a..6619e83fd9 100644 --- a/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js +++ b/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js @@ -54,7 +54,7 @@ describe('GET /heroes/:heroId', () => { expect(heroRes.profile).to.have.all.keys(['name']); }); - it('returns only necessary hero data given username with display case', async () => { + it('returns only necessary hero data given username', async () => { let hero = await generateUser({ contributor: {tier: 23}, }); @@ -68,15 +68,9 @@ describe('GET /heroes/:heroId', () => { expect(heroRes.profile).to.have.all.keys(['name']); }); - it('returns hero data given username without case sensitivity', async () => { - let hero = await generateUser({}, 'TestUpperCaseName123'); - let heroRes = await user.get(`/hall/heroes/${hero.auth.local.username.toLowerCase()}`); - - expect(heroRes).to.have.all.keys([ - '_id', 'id', 'balance', 'profile', 'purchased', - 'contributor', 'auth', 'items', - ]); - expect(heroRes.auth.local).not.to.have.keys(['salt', 'hashed_password']); - expect(heroRes.profile).to.have.all.keys(['name']); + it('returns correct hero using search with difference case', async () => { + let hero = await generateUser({}, { username: 'TestUpperCaseName123' }); + let heroRes = await user.get(`/hall/heroes/TestuPPerCasEName123`); + expect(heroRes.auth.local.username).to.equal('TestUpperCaseName123'); }); }); diff --git a/test/helpers/api-integration/v3/object-generators.js b/test/helpers/api-integration/v3/object-generators.js index 00ef85a955..403df7710a 100644 --- a/test/helpers/api-integration/v3/object-generators.js +++ b/test/helpers/api-integration/v3/object-generators.js @@ -14,14 +14,15 @@ import * as Tasks from '../../../../website/server/models/task'; // , you can do so by passing in the full path as a string: // { 'items.eggs.Wolf': 10 } // -// To manually set a username pass it as the second parameter. -// If no password is passed or it is falsy then a username will -// be auto-generated. -// Example: generateUser({}, 'TestName') adds user with the 'TestName' username. -export async function generateUser (update = {}, manualUsername = null) { - let username = manualUsername || (Date.now() + generateUUID()).substring(0, 20); - let password = 'password'; - let email = `${username}@example.com`; +// To manually set a username, email or password pass it in as +// an object for the second parameter. Only overrides need to be +// added. Items that don't exist will be autogenerated. +// Example: generateUser({}, { username: 'TestName' }) adds user +// with the 'TestName' username. +export async function generateUser (update = {}, overrides = {}) { + let username = overrides.username || (Date.now() + generateUUID()).substring(0, 20); + let password = overrides.password || 'password'; + let email = overrides.email || `${username}@example.com`; let user = await requester().post('/user/auth/local/register', { username, From b387d7712833e3dc1f25694777b7b7c1951d833d Mon Sep 17 00:00:00 2001 From: Randi Miller Date: Fri, 22 Mar 2019 16:18:58 -0400 Subject: [PATCH 4/4] Lint fixes --- test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js | 4 ++-- test/helpers/api-integration/v3/object-generators.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js b/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js index 6619e83fd9..4b5bab8f0b 100644 --- a/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js +++ b/test/api/v3/integration/hall/GET-hall_heroes_heroId.test.js @@ -69,8 +69,8 @@ describe('GET /heroes/:heroId', () => { }); it('returns correct hero using search with difference case', async () => { - let hero = await generateUser({}, { username: 'TestUpperCaseName123' }); - let heroRes = await user.get(`/hall/heroes/TestuPPerCasEName123`); + await generateUser({}, { username: 'TestUpperCaseName123' }); + let heroRes = await user.get('/hall/heroes/TestuPPerCasEName123'); expect(heroRes.auth.local.username).to.equal('TestUpperCaseName123'); }); }); diff --git a/test/helpers/api-integration/v3/object-generators.js b/test/helpers/api-integration/v3/object-generators.js index 403df7710a..7a0e2cbcf8 100644 --- a/test/helpers/api-integration/v3/object-generators.js +++ b/test/helpers/api-integration/v3/object-generators.js @@ -17,7 +17,7 @@ import * as Tasks from '../../../../website/server/models/task'; // To manually set a username, email or password pass it in as // an object for the second parameter. Only overrides need to be // added. Items that don't exist will be autogenerated. -// Example: generateUser({}, { username: 'TestName' }) adds user +// Example: generateUser({}, { username: 'TestName' }) adds user // with the 'TestName' username. export async function generateUser (update = {}, overrides = {}) { let username = overrides.username || (Date.now() + generateUUID()).substring(0, 20);