-
Notifications
You must be signed in to change notification settings - Fork 142
feat: Create admin protected endpoint for creating users #981
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
Open
dcoric
wants to merge
2
commits into
finos:main
Choose a base branch
from
G-Research:denis-coric/create-user
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+386
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -483,6 +483,114 @@ describe('test git-proxy-cli', function () { | |||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// *** create user *** | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
describe('test git-proxy-cli :: create-user', function () { | ||||||||||||||||||||||||||
dcoric marked this conversation as resolved.
Show resolved
Hide resolved
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. These functions fix one of the failing CLI tests:
Suggested change
|
||||||||||||||||||||||||||
it('attempt to create user should fail when server is down', async function () { | ||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||
// start server -> login -> stop server | ||||||||||||||||||||||||||
await helper.startServer(service); | ||||||||||||||||||||||||||
await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); | ||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||
await helper.closeServer(service.httpServer); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit`; | ||||||||||||||||||||||||||
const expectedExitCode = 2; | ||||||||||||||||||||||||||
const expectedMessages = null; | ||||||||||||||||||||||||||
const expectedErrorMessages = ['Error: Create User:']; | ||||||||||||||||||||||||||
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
it('attempt to create user should fail when not authenticated', async function () { | ||||||||||||||||||||||||||
await helper.removeCookiesFile(); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit`; | ||||||||||||||||||||||||||
const expectedExitCode = 1; | ||||||||||||||||||||||||||
const expectedMessages = null; | ||||||||||||||||||||||||||
const expectedErrorMessages = ['Error: Create User: Authentication required']; | ||||||||||||||||||||||||||
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
it('attempt to create user should fail when not admin', async function () { | ||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||
await helper.startServer(service); | ||||||||||||||||||||||||||
await helper.runCli( | ||||||||||||||||||||||||||
`npx -- @finos/git-proxy-cli login --username testuser --password testpassword`, | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit`; | ||||||||||||||||||||||||||
const expectedExitCode = 3; | ||||||||||||||||||||||||||
const expectedMessages = null; | ||||||||||||||||||||||||||
const expectedErrorMessages = ['Error: Create User: Authentication required']; | ||||||||||||||||||||||||||
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); | ||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||
await helper.closeServer(service.httpServer); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
it('attempt to create user should fail with missing required fields', async function () { | ||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||
await helper.startServer(service); | ||||||||||||||||||||||||||
await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --email [email protected] --gitAccount newgit`; | ||||||||||||||||||||||||||
const expectedExitCode = 4; | ||||||||||||||||||||||||||
dcoric marked this conversation as resolved.
Show resolved
Hide resolved
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. Oddly, this fix didn't get applied previously (will fix the test):
Suggested change
|
||||||||||||||||||||||||||
const expectedMessages = null; | ||||||||||||||||||||||||||
const expectedErrorMessages = ['Error: Create User: Missing required fields']; | ||||||||||||||||||||||||||
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); | ||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||
await helper.closeServer(service.httpServer); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
it('should successfully create a new user', async function () { | ||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||
await helper.startServer(service); | ||||||||||||||||||||||||||
await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit`; | ||||||||||||||||||||||||||
const expectedExitCode = 0; | ||||||||||||||||||||||||||
const expectedMessages = ["User 'newuser' created successfully"]; | ||||||||||||||||||||||||||
const expectedErrorMessages = null; | ||||||||||||||||||||||||||
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Verify we can login with the new user | ||||||||||||||||||||||||||
await helper.runCli( | ||||||||||||||||||||||||||
`npx -- @finos/git-proxy-cli login --username newuser --password newpass`, | ||||||||||||||||||||||||||
0, | ||||||||||||||||||||||||||
[`Login "newuser" <[email protected]>: OK`], | ||||||||||||||||||||||||||
null, | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||
await helper.closeServer(service.httpServer); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
it('should successfully create a new admin user', async function () { | ||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||
await helper.startServer(service); | ||||||||||||||||||||||||||
await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const cli = `npx -- @finos/git-proxy-cli create-user --username newadmin --password newpass --email [email protected] --gitAccount newgit --admin`; | ||||||||||||||||||||||||||
const expectedExitCode = 0; | ||||||||||||||||||||||||||
const expectedMessages = ["User 'newadmin' created successfully"]; | ||||||||||||||||||||||||||
const expectedErrorMessages = null; | ||||||||||||||||||||||||||
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Verify we can login with the new admin user | ||||||||||||||||||||||||||
await helper.runCli( | ||||||||||||||||||||||||||
`npx -- @finos/git-proxy-cli login --username newadmin --password newpass`, | ||||||||||||||||||||||||||
0, | ||||||||||||||||||||||||||
[`Login "newadmin" <[email protected]> (admin): OK`], | ||||||||||||||||||||||||||
null, | ||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
} finally { | ||||||||||||||||||||||||||
await helper.closeServer(service.httpServer); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// *** tests require push in db *** | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
describe('test git-proxy-cli :: git push administration', function () { | ||||||||||||||||||||||||||
|
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
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.
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.
Linter issue here:
351:11 error 'response' is assigned a value but never used no-unused-vars