Skip to content

Commit

Permalink
Use Gravatar (fix #305) and fix all broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bates64 committed May 1, 2018
1 parent ef20068 commit 0a45d64
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/client/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const theme = {
'--table-cell-bg': '#25292f',
'--table-cell-fg': 'var(--page-dim-fg)',

'--toast-bg': '#16191c',

'--messageEditor-fg': 'var(--gray-700)',
'--messageEditor-bg': '#25292f',
'--messageEditor-border-color': '#3c4144',
Expand Down
2 changes: 1 addition & 1 deletion packages/server/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ module.exports = function makeCommonUtils({db, connectedSocketsMap}) {
}

const emailToAvatarURL = memoize(email =>
`https://seccdn.libravatar.org/avatar/${email ? md5(email) : ''}?d=retro`
`https://gravatar.com/avatar/${email ? md5(email) : ''}?d=retro`
)

const isUserOnline = function(userID) {
Expand Down
28 changes: 27 additions & 1 deletion packages/server/test/_serverUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const shortid = require('shortid')
const makeCommonUtils = require('../common')
const { makeMiddleware } = require('../middleware')
const makeSerializers = require('../serialize')
const { setSetting, serverPropertiesID, getAllSettings } = require('../settings')

const testWithServer = async (port, cb) => {
const server = await spawn(port)
Expand Down Expand Up @@ -41,8 +42,33 @@ const makeUser = async (server, port, inUsername = undefined, inPassword = undef
}

const giveOwnerRole = async (server, userID) => {
let ownerRole = await server.db.roles.findOne({name: 'Owner'})

if (!ownerRole) {
const name = 'Owner'
const permissions = {}

for (const key of require('../roles').permissionKeys) {
permissions[key] = true // Grant every permission
}

const role = await server.db.roles.insert({
name, permissions
})

// Also add the role to the role prioritization order
const { rolePrioritizationOrder } = await getAllSettings(server.db.settings, serverPropertiesID)
rolePrioritizationOrder.unshift(role._id)
await setSetting(
server.db.settings, serverPropertiesID,
'rolePrioritizationOrder', rolePrioritizationOrder
)

ownerRole = role
}

await server.db.users.update({_id: userID}, {
$push: {roleIDs: (await server.db.roles.findOne({name: 'Owner'}))._id}
$push: {roleIDs: ownerRole._id}
})
}

Expand Down
3 changes: 1 addition & 2 deletions packages/server/test/api-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ test('GET /api/roles (default roles)', t => {

t.deepEqual(Object.keys(response), ['roles'])

t.is(response.roles.length, 4)
t.is(response.roles.length, 3)
t.true(response.roles.some(r => r.id === '_everyone'))
t.true(response.roles.some(r => r.id === '_user'))
t.true(response.roles.some(r => r.id === '_guest'))
t.true(response.roles.some(r => r.name === 'Owner'))
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/api-users.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { test } = require('ava')
const { testWithServer, makeUser, makeAdmin, enableAuthorization } = require('./_serverUtil')
const { testWithServer, makeUser, makeOwner, enableAuthorization } = require('./_serverUtil')
const fetch = require('./_fetch')

let portForApiUserTests = 30000
Expand Down Expand Up @@ -141,7 +141,7 @@ test('GET /api/username-available/:username', t => {
test('PATCH /api/users/:id', t => {
return testWithServer(portForApiUserTests++, async ({ server, port }) => {
const { user, sessionID: userSessionID } = await makeUser(server, port, 'test_user', 'password')
const { admin, sessionID: adminSessionID } = await makeAdmin(server, port)
const { admin, sessionID: adminSessionID } = await makeOwner(server, port)

const getUser = () => fetch(port, '/users/' + user.id, {
sessionID: userSessionID
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ test('md5', t => {
test('emailToAvatarURL', t => {
return testWithServer(portForCommonTests++, ({ util }) => {
t.is(util.emailToAvatarURL('[email protected]'),
`https://seccdn.libravatar.org/avatar/${util.md5('[email protected]')}?d=retro`
`https://gravatar.com/avatar/${util.md5('[email protected]')}?d=retro`
)
t.is(util.emailToAvatarURL(''),
'https://seccdn.libravatar.org/avatar/?d=retro'
'https://gravatar.com/avatar/?d=retro'
)
})
})
Expand Down

0 comments on commit 0a45d64

Please sign in to comment.