Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
Debug why private repo access does not work (#444)
Browse files Browse the repository at this point in the history
* debug why private repo access does not work

* fix tests
  • Loading branch information
prayerslayer authored Sep 15, 2016
1 parent 9d0d4e3 commit ea90613
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
11 changes: 10 additions & 1 deletion server/routes/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import nconf from '../nconf'
import passport from 'koa-passport'
import UserHandler from '../handler/UserHandler'
import * as AccessLevel from '../../common/AccessLevels'
import { logger } from '../../common/debug'

const info = logger('api-auth', 'info')

/**
* Login endpoint.
Expand All @@ -27,14 +30,20 @@ export function login(router) {
*/
export async function ensureModeMiddleware(ctx, next) {
const user = ctx.req.user
if (!!user) {
info(`ensureMode start`)
if (!!user && !!user.json) {
info(`ensureMode:${user.json.login}`)
const {access_level} = await UserHandler.onGet(user.id)
info(`ensureMode:${user.json.login}: level = "${access_level}" (DB)`)
const accessLevelCookie = ctx.cookies.get(AccessLevel.COOKIE_NAME)
info(`ensureMode:${user.json.login}: level = "${accessLevelCookie}" (COOKIE)`)
if (access_level !== accessLevelCookie) {
info(`ensureMode:${user.json.login}: MISMATCH! CHANGING TO "${access_level}"!`)
// database beats cookie
ctx.redirect(`/change-access-level?level=${access_level}`)
}
}
info(`ensureMode end`)
// for some reason only works with await
await next()
}
Expand Down
7 changes: 4 additions & 3 deletions test/passport/MockStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ const props = {
id: 1,
accessToken: 'abcd',
username: 'test',
_json: {
id: 1
json: {
id: 1,
login: 'test',
}
}
}

export function setUserId(id) {
props.user.id = id
props.user._json.id = id
props.user.json.id = id
}

export function setUserName(name) {
Expand Down
3 changes: 2 additions & 1 deletion test/server/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ describe('API', () => {

try {
// Initialize database
await db.sync()
await db.createSchemas()
await db._sync()

// Load fixtures
fixtures.user = testUser
Expand Down
3 changes: 2 additions & 1 deletion test/server/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ describe('Server', () => {

before(async(done) => {
try {
await db.sync()
await db.createSchemas()
await db._sync()
await request.get('/auth/github') // Initialize session
done()
} catch (err) {
Expand Down

0 comments on commit ea90613

Please sign in to comment.