Skip to content
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

Use native go method to get current user rather than environment variable #4930

Merged
merged 4 commits into from
Oct 18, 2018

Conversation

SagePtr
Copy link
Contributor

@SagePtr SagePtr commented Sep 13, 2018

Fixes #1640, #4894

Native "os/user" go package has good function to retrieve current user, rather than relying on USER environment variable.

If getting current user doesn't work on target OS (for example, not yet implemented for it) - it falls back to old implementation with environment variables.

Unit test also changed, old one won't work because USER environment variable spoofing doesn't work anymore (unless os/user is not implemented for OS under which tests are run), now it just compares CurrentUser() with whoami command output (skipped on Windows where whoami behaves different way).

For Windows OS with "domain\username" format, only second part (username) is returned to match previous behavior and trim unnecessary prefix.

@bkcsoft bkcsoft added the lgtm/need 1 This PR needs approval from one additional maintainer to be merged. label Sep 13, 2018
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Sep 13, 2018
@lafriks lafriks added this to the 1.7.0 milestone Sep 13, 2018
@lafriks lafriks added the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Sep 13, 2018
@lafriks
Copy link
Member

lafriks commented Sep 13, 2018

Blocked until 1.6.0-rc1 is released

Copy link
Member

@sapk sapk 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 just need a little change.

modules/user/user_test.go Outdated Show resolved Hide resolved
@bkcsoft bkcsoft added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Sep 18, 2018
@lunny lunny removed the status/blocked This PR cannot be merged yet, i.e. because it depends on another unmerged PR label Oct 18, 2018
@codecov-io
Copy link

Codecov Report

Merging #4930 into master will increase coverage by <.01%.
The diff coverage is 27.27%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #4930      +/-   ##
=========================================
+ Coverage    37.4%   37.4%   +<.01%     
=========================================
  Files         306     306              
  Lines       45378   45389      +11     
=========================================
+ Hits        16974   16980       +6     
- Misses      25949   25954       +5     
  Partials     2455    2455
Impacted Files Coverage Δ
modules/user/user.go 23.52% <27.27%> (-76.48%) ⬇️
models/repo_list.go 63.37% <0%> (+1.16%) ⬆️
models/repo_indexer.go 52.11% <0%> (+2.54%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 637c5fe...1ea5eea. Read the comment docs.

@lunny lunny merged commit eb0c848 into go-gitea:master Oct 18, 2018
@SagePtr SagePtr deleted the golang-currentuser branch May 2, 2019 15:24
@SagePtr SagePtr restored the golang-currentuser branch May 2, 2019 15:24
@SagePtr SagePtr deleted the golang-currentuser branch May 2, 2019 15:24
@SagePtr SagePtr restored the golang-currentuser branch May 2, 2019 15:24
@SagePtr SagePtr deleted the golang-currentuser branch May 2, 2019 15:29
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CurrentUsername is not always reliable
7 participants