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

os/user: test fails on windows #4113

Closed
alexbrainman opened this issue Sep 20, 2012 · 6 comments
Closed

os/user: test fails on windows #4113

alexbrainman opened this issue Sep 20, 2012 · 6 comments

Comments

@alexbrainman
Copy link
Member

Hi All,

I am couple of days into go. My working os is windows.
I wanted to work with a recent developer build of go. Since there were no releases after
go1.0.2, I tried building the source.

> hg tip
changeset:   14138:979c5e5b1308

The windows build completed with 3 test failures as below:

    --- FAIL: TestCurrent (21.51 seconds)
    user_test.go:34:        Current: The RPC server is unavailable.
    --- FAIL: TestLookup (0.00 seconds)
    user_test.go:74:        Current: The RPC server is unavailable.
    --- FAIL: TestLookupId (0.00 seconds)
    user_test.go:90:        Current: The RPC server is unavailable.


My questions:

1. There were no build logs apart from the messages on stdio. I couldn't find any
options in all.bat or make.bat either. Is there anyway to enable build logging?
2. How to invoke only failed test by name instead of package level ?
3. How to get more debugging information? (stack-trace or entry-exit logs) The go test
verbose option doesn't seem to through any more useful information

4. What should I do next with the test failure? Below is my understanding of the cause -
is this a bug or some environment issue on my system?

For the above error, I introduced fmt.Println()'s and the impression I get is that the
failure is in:

    os/user/lookup_windows.go -> Current() -> newUser() -> lookupFullName()

    newUser() has gets all parameters with exception of name in the below struct.
    u := &User{
    Uid:      uid,
    Gid:      gid,
    Username: domainAndUser,
    Name:     name,
    HomeDir:  dir,
    }
    To resolve the OS name to the actual name it calls lookupFullName() to resolve with domain controller and fails.

    My laptop was not connected to the network to which the user belongs. I tried the same after connecting to the network and the test succeeded.


What is the expected behavior of Current(). Since it already has domainAndUser, why not
respond with these details instead of failing.
Is there any other interface for fetching currently logged OS user?

best regards
Shivakumar GN
@shivakumargn
Copy link
Contributor

Comment 1:

[1] A suitable behavior for user.Current() might be to return only what a API user may
intuitively expect: a OS user name as a string (instead of User struct)
But unfortunately, user.Current() is an interface that is already present in officially
released version of Go :(
Next best option might be to return the user struct but fill only the username with rest
of the fields in initialized state.
This avoids a network access when not needed thereby saving time and not needing error
handling when not needed.
[2] Relevance for other exported functions
* The problem seems to exist in windows version of user.Lookup() and user.LookupId() as
well
* This problem is not as relevant for posix systems since AFAIK, a network authenticated
user cannot login if the auth server is down. Nevertheless, based on change done for the
windows implementation, it is best modified accordingly for a consistent behavior.
[3] If wanting to expose different user information one may consider introducing
additional exported functions.

@alexbrainman
Copy link
Member Author

Comment 2:

This issue is not about changing any interface. It is about making our current test PASS
in every possible situation. You have discovered a scenario of when our test fails, so
we should adjust things accordingly make it PASS. I do not know how to do it yet.
Alex

@shivakumargn
Copy link
Contributor

Comment 3:

Please check the suitability of the patch I am submitting
(I am having problems with codereview extension as of now)
It is possible to get the tests to pass with the below change to lookupFullName()
Hence the comment above behavior of the interface in point #1
func lookupFullName(domain, username, domainAndUser string) (string, error) {
    return username, nil
}
I am attaching a patch as a fix candidate. I have tested it with for computer part of
the domain as well as without.
Changes are as below:
lookupFullName() instead of calling syscall.TranslateAccountName() calls
syscall.GetUserNameEx()
The expected behavior of GetUserNameEx() is that if the computer is not part of the
domain it picks the information from local OS cache else it gets from domain controller.
One quirk here is that - as per documentation (check URLs below) if the user is not in a
domin, GetUserNameEx() is expected to support only NameSamCompatible. But in reality, it
actually supports NameDisplay as per test results - this is good for this issue.
http://msdn.microsoft.com/en-us/library/ms902883.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724435(v=vs.85).aspx

Attachments:

  1. go_bug_4113.patch (2400 bytes)

@shivakumargn
Copy link
Contributor

Comment 4:

It is possible to get the tests to pass with the below change to lookupFullName(). Hence
my comment about interface behavior. For the current interface this might be OK.
func lookupFullName(domain, username, domainAndUser string) (string, error) {
    return username, nil
}
Seems like a better fix is possible as below:
lookupFullName() instead of calling syscall.TranslateAccountName() calls
syscall.GetUserNameEx()
The expected behavior of GetUserNameEx() is that if the computer is not part of the
domain it picks the information from local OS cache else it gets from domain controller.
I have tested it with both positive & negative cases.
One quirk here is that - as per documentation (URLs below) if the user is not in a
domin, GetUserNameEx() is expected to support only NameSamCompatible. But in reality, it
actually supports NameDisplay as per test results - this is good for this issue.
This is what has been used since not using it would reduce the situation to the trivial
fix I suggested at the start.
http://msdn.microsoft.com/en-us/library/ms902883.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724435(v=vs.85).aspx

Attachments:

  1. go_bug_4113.patch (2400 bytes)

@alexbrainman
Copy link
Member Author

Comment 5:

Perhaps,
func lookupFullName(domain, username, domainAndUser string) (string, error) {
    return username, nil
}
will work, but that is cheating. The lookupFullName should uncover user's "full name",
not user "account name". Perhaps, in some situations that is apropriate, but not as a
general solution.
Alex

@alexbrainman
Copy link
Member Author

Comment 6:

This issue was closed by revision 5f7f906.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants