-
Notifications
You must be signed in to change notification settings - Fork 146
fix: checkUserPushPermission push failure on name #1110
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
Closed
+332
−76
Closed
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ca2faf7
fix: checkUserPushPermission push failure on URL mismatch
andypols 360cc82
Merge branch 'main' into check-push-with-url
andypols ffcf17b
Merge branch 'add-get-repo-by-url' into check-push-with-url
andypols 81d903d
Merge branch 'main' into check-push-with-url
andypols fd8f94d
chore: fix tests post merge
andypols c1b1de2
chore: update with db tests from #1109
andypols File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 7 additions & 25 deletions
32
src/proxy/processors/push-action/checkRepoInAuthorisedList.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 20 additions & 41 deletions
61
src/proxy/processors/push-action/checkUserPushPermission.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
const repoModule = require('../../../src/db/file/repo'); | ||
|
||
describe('File DB', () => { | ||
let sandbox; | ||
|
||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('getRepo', () => { | ||
it('should get the repo using the name', async () => { | ||
const repoData = { | ||
name: 'sample', | ||
users: { canPush: [] }, | ||
url: 'http://example.com/sample-repo', | ||
}; | ||
|
||
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData)); | ||
|
||
const result = await repoModule.getRepo('Sample'); | ||
expect(result).to.equal(repoData); | ||
}); | ||
}); | ||
|
||
describe('getRepoByUrl', () => { | ||
it('should get the repo using the url', async () => { | ||
const repoData = { | ||
name: 'sample', | ||
users: { canPush: [] }, | ||
url: 'https://github.com/finos/git-proxy', | ||
}; | ||
|
||
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData)); | ||
|
||
const result = await repoModule.getRepoByUrl('https://github.com/finos/git-proxy'); | ||
expect(result).to.equal(repoData); | ||
}); | ||
|
||
it('should get the repo using the url, stripping off the .git', async () => { | ||
const repoData = { | ||
name: 'sample', | ||
users: { canPush: [] }, | ||
url: 'https://github.com/finos/git-proxy', | ||
}; | ||
|
||
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData)); | ||
|
||
const result = await repoModule.getRepoByUrl('https://github.com/finos/git-proxy.git'); | ||
|
||
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/git-proxy'}))).to.be.true; | ||
expect(result).to.equal(repoData); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const { expect } = require('chai'); | ||
const sinon = require('sinon'); | ||
const proxyqquire = require('proxyquire'); | ||
|
||
const repoCollection = { | ||
findOne: sinon.stub(), | ||
}; | ||
|
||
const connectionStub = sinon.stub().returns(repoCollection); | ||
|
||
const { getRepo, getRepoByUrl } = proxyqquire('../../../src/db/mongo/repo', { | ||
'./helper': { connect: connectionStub }, | ||
}); | ||
|
||
describe('MongoDB', () => { | ||
afterEach(function () { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('getRepo', () => { | ||
it('should get the repo using the name', async () => { | ||
const repoData = { | ||
name: 'sample', | ||
users: { canPush: [] }, | ||
url: 'http://example.com/sample-repo', | ||
}; | ||
repoCollection.findOne.resolves(repoData); | ||
|
||
const result = await getRepo('Sample'); | ||
expect(result).to.equal(repoData); | ||
expect(connectionStub.calledWith('repos')).to.be.true; | ||
expect(repoCollection.findOne.calledWith({ name: { $eq: 'sample' } })).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('getRepoByUrl', () => { | ||
it('should get the repo using the url', async () => { | ||
const repoData = { | ||
name: 'sample', | ||
users: { canPush: [] }, | ||
url: 'https://github.com/finos/git-proxy', | ||
}; | ||
repoCollection.findOne.resolves(repoData); | ||
|
||
const result = await getRepoByUrl('https://github.com/finos/git-proxy'); | ||
expect(result).to.equal(repoData); | ||
expect(connectionStub.calledWith('repos')).to.be.true; | ||
expect( | ||
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy' } }), | ||
andypols marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
).to.be.true; | ||
}); | ||
|
||
it('should get the repo using the url, stripping off the .git', async () => { | ||
const repoData = { | ||
name: 'sample', | ||
users: { canPush: [] }, | ||
url: 'https://github.com/finos/git-proxy', | ||
}; | ||
repoCollection.findOne.resolves(repoData); | ||
|
||
const result = await getRepoByUrl('https://github.com/finos/git-proxy.git'); | ||
expect(result).to.equal(repoData); | ||
expect(connectionStub.calledWith('repos')).to.be.true; | ||
expect( | ||
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy' } }), | ||
).to.be.true; | ||
}); | ||
|
||
it('should get the repo using the url, ignoring the case', async () => { | ||
const repoData = { | ||
name: 'sample', | ||
users: { canPush: [] }, | ||
url: 'https://github.com/finos/git-proxy', | ||
}; | ||
repoCollection.findOne.resolves(repoData); | ||
|
||
const result = await getRepoByUrl('https://github.com/Finos/Git-Proxy.git'); | ||
expect(result).to.equal(repoData); | ||
expect(connectionStub.calledWith('repos')).to.be.true; | ||
expect( | ||
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy' } }), | ||
).to.be.true; | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.