Skip to content

Conversation

@dcoric
Copy link
Contributor

@dcoric dcoric commented Apr 15, 2025

Introduce a new API endpoint for creating users and a corresponding command in the git-proxy-cli to interact with this endpoint. The new functionality enables administrators to create new user accounts via the CLI.

Changes

  • Added a createUser function to packages/git-proxy-cli/index.js that handles user creation via an API call. It checks for authentication cookies and makes a POST request to the /api/auth/create-user endpoint.
  • Added a create-user command to the CLI using yargs in packages/git-proxy-cli/index.js. This command takes username, password, email, gitAccount, and an optional admin flag as arguments.
  • Created a new route /api/auth/create-user in src/service/routes/auth.js that handles the user creation request. It checks for admin privileges and validates the request body before creating the user in the database.
  • Added tests for the create-user command to packages/git-proxy-cli/test/testCli.test.js, covering scenarios such as server down, no authentication, missing required fields and successful user creation.
  • Added tests for the /api/auth/create-user route to test/testLogin.test.js to verify authentication, authorization, data validation, and successful user creation.

Impact

  • Introduces a new create-user command to the git-proxy-cli, enabling administrators to create user accounts directly from the command line.
  • The /api/auth/create-user endpoint is now available, allowing authenticated administrators to create new user accounts.
  • Depends on the axios library in packages/git-proxy-cli/index.js.
  • Relies on the database interaction functions in src/service/routes/auth.js to create user records.
  • The new feature requires the user to be authenticated as an admin to create new users.

Resolves #980

@netlify
Copy link

netlify bot commented Apr 15, 2025

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit e3bb228
🔍 Latest deploy log https://app.netlify.com/projects/endearing-brigadeiros-63f9d0/deploys/68b858ece7d4ec0009b27549

@kriswest
Copy link
Contributor

You could replace or remove this test, which is currently skipped, with your new tests:

it('should be able to create a new user', async function () {
const res = await chai.request(app).post('/api/auth/profile').set('Cookie', `${cookie}`).send({
username: 'login-test-user',
email: '[email protected]',
gitAccount: 'test123',
admin: true,
});
res.should.have.status(200);
}).skip();

@dcoric dcoric changed the title [Feature]: Create admin protected endpoint for creating users [feat]: Create admin protected endpoint for creating users Apr 22, 2025
@dcoric dcoric changed the title [feat]: Create admin protected endpoint for creating users feat: Create admin protected endpoint for creating users Apr 22, 2025
@dcoric dcoric force-pushed the denis-coric/create-user branch 2 times, most recently from d6f580d to 271916f Compare May 16, 2025 11:02
Copy link
Contributor

@jescalada jescalada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good! I've had some problems executing the tests, although some issues were present before.

Let me know if I'm missing something! 🙂

@jescalada
Copy link
Contributor

Also, it would be very helpful to execute the git-proxy-cli tests in the CI, so we don't accidentally introduce bugs...

@JamieSlome
Copy link
Member

What's the status of this PR? @jescalada @dcoric

@dcoric
Copy link
Contributor Author

dcoric commented Jul 1, 2025

What's the status of this PR? @jescalada @dcoric

I’m currently OOO but I plan to polish this up by the end of the week. I will ping here once it is ready for another review

@dcoric dcoric force-pushed the denis-coric/create-user branch 2 times, most recently from 3f7a0be to a4d3526 Compare July 14, 2025 12:32
@codecov
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.86%. Comparing base (11ec0ca) to head (e3bb228).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #981      +/-   ##
==========================================
+ Coverage   82.78%   82.86%   +0.07%     
==========================================
  Files          66       66              
  Lines        2783     2795      +12     
  Branches      332      332              
==========================================
+ Hits         2304     2316      +12     
  Misses        431      431              
  Partials       48       48              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dcoric
Copy link
Contributor Author

dcoric commented Jul 14, 2025

@JamieSlome @jescalada I've implemented all the requested changes. I ran into some challenges with the tests, but everything should be working correctly now. When you have a moment, could you please review the updates? It should be all set for merging.

Let me know if you spot anything else that needs adjustment - otherwise, it's good to go!

@dcoric dcoric force-pushed the denis-coric/create-user branch from a4d3526 to d4d9020 Compare August 1, 2025 13:33
Copy link
Contributor

@jescalada jescalada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far 👍🏼 I spent some time finding fixes for the failing CLI tests. Hopefully committing those directly will fix things.

- Add proper test setup/teardown for create-user tests
- Fix missing required fields test to use empty password instead of omitting it
- Use unique usernames with timestamps to prevent conflicts between test runs
- Add proper cleanup for created users in finally blocks
- Ensure all 42 CLI tests now pass consistently
Copy link
Contributor

@jescalada jescalada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after fixing a flaky test!

We should probably merge this in first, and then the CLI TS refactor PR. I don't think it'll be too hard to add these changes to the PR 🤔

dcoric and others added 4 commits September 3, 2025 14:54
Fixes flaky test due to duplicate emails

Co-authored-by: Juan Escalada <[email protected]>
Signed-off-by: Denis Ćorić <[email protected]>
Fixes flaky test due to duplicate email

Co-authored-by: Juan Escalada <[email protected]>
Signed-off-by: Denis Ćorić <[email protected]>
Adds an error log in case of failed DB cleanup

Co-authored-by: Juan Escalada <[email protected]>
Signed-off-by: Denis Ćorić <[email protected]>
@jescalada jescalada merged commit 1232fa5 into finos:main Sep 3, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: User Creation Endpoint and CLI Command [Feature]: Create admin protected endpoint for creating users

4 participants