-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite and test Github auth logic, separating standard and search quota #1205
Changes from all commits
202b508
a105e98
054314a
e045dbf
8617f46
815ec67
224266d
d138ce0
188d389
d99d095
71ccb19
ee5dba1
06047cd
7cc3ea6
8f587bd
139b8ad
c49f6d9
afe0da5
d67e875
b03df7d
e744f3c
31f7e8c
a654fb1
798b46e
5addd68
1f86e85
b949ecc
58fbda3
df6f303
5bcf33c
c68bf49
b024e47
f67d335
71e19ca
bdd72af
5e46181
b01e92b
a65c4b0
52c4e42
4134d27
2f8efda
f3119f8
9b152f1
c849a0e
3d625b7
1966a03
030296b
89dfce2
c44ef30
d8b3802
9654883
2a4f2bc
9b3d5c6
b92de26
d854927
367f202
0e2b471
0ee7eed
8d74c63
e035788
0342509
baf33ac
2ffc965
d050f48
e334cc8
35b8e44
8933591
ad4e5ee
585332c
eb372a9
4bcc876
19f398c
375d609
7ea08cc
a84dc89
2248429
96e5e82
e37d076
b4d8dda
d6258e4
5f68f3a
d187d10
76c2e80
4d8dd16
6fda89e
c6576fa
cebe1c8
023953d
78773e0
7320221
ac4619c
fd63acc
f3b9191
4dd8cd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,8 @@ const tmp = require('tmp') | |
const readFile = require('fs-readfile-promise') | ||
const { expect } = require('chai') | ||
const FsTokenPersistence = require('./fs-token-persistence') | ||
const githubAuth = require('./github-auth') | ||
|
||
describe('File system token persistence', function() { | ||
beforeEach(githubAuth.removeAllTokens) | ||
afterEach(githubAuth.removeAllTokens) | ||
|
||
let path, persistence | ||
beforeEach(function() { | ||
path = tmp.tmpNameSync() | ||
|
@@ -19,8 +15,8 @@ describe('File system token persistence', function() { | |
|
||
context('when the file does not exist', function() { | ||
it('does nothing', async function() { | ||
await persistence.initialize() | ||
expect(githubAuth.getAllTokenIds()).to.deep.equal([]) | ||
const tokens = await persistence.initialize() | ||
expect(tokens).to.deep.equal([]) | ||
}) | ||
|
||
it('saving creates an empty file', async function() { | ||
|
@@ -41,18 +37,17 @@ describe('File system token persistence', function() { | |
}) | ||
calebcartwright marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
it('loads the contents', async function() { | ||
await persistence.initialize() | ||
expect(githubAuth.getAllTokenIds()).to.deep.equal(initialTokens) | ||
const tokens = await persistence.initialize() | ||
expect(tokens).to.deep.equal(initialTokens) | ||
}) | ||
|
||
context('when tokens are added', function() { | ||
it('saves the change', async function() { | ||
const newToken = 'e'.repeat(40) | ||
const expected = initialTokens.slice() | ||
const expected = Array.from(initialTokens) | ||
expected.push(newToken) | ||
|
||
await persistence.initialize() | ||
githubAuth.addGithubToken(newToken) | ||
await persistence.noteTokenAdded(newToken) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i know that the function name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I'd vote for |
||
|
||
const savedTokens = JSON.parse(await readFile(path)) | ||
|
@@ -67,7 +62,6 @@ describe('File system token persistence', function() { | |
|
||
await persistence.initialize() | ||
|
||
githubAuth.rmGithubToken(toRemove) | ||
await persistence.noteTokenRemoved(toRemove) | ||
|
||
const savedTokens = JSON.parse(await readFile(path)) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
const redis = require('redis') | ||
const { promisify } = require('util') | ||
const log = require('./log') | ||
const githubAuth = require('./github-auth') | ||
const TokenPersistence = require('./token-persistence') | ||
|
||
class RedisTokenPersistence extends TokenPersistence { | ||
|
@@ -21,16 +20,8 @@ class RedisTokenPersistence extends TokenPersistence { | |
|
||
const lrange = promisify(this.client.lrange).bind(this.client) | ||
|
||
let tokens | ||
try { | ||
tokens = await lrange(this.key, 0, -1) | ||
} catch (e) { | ||
log.error(e) | ||
} | ||
|
||
tokens.forEach(tokenString => { | ||
githubAuth.addGithubToken(tokenString) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now the caller's responsibility. |
||
const tokens = await lrange(this.key, 0, -1) | ||
return tokens | ||
} | ||
|
||
async stop() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the caller's responsibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first time looking at this part of the code, but it looks like this change here decouples this persistence engine from github specifics, which creates the possibility of this being reusable for other services?
I've no idea if there's a similar need in other services, but 👍 either way!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I've been working on this for so long I almost forgot it was still coupled at this stage. 😝
I believe the pooling is also needed for #541.