Exemplo n.º 1
0
 // [Fact]
 private void DumpUserNameFormats()
 {
     foreach (EXTENDED_NAME_FORMAT format in Enum.GetValues(typeof(EXTENDED_NAME_FORMAT)))
     {
         try
         {
             string name = SystemInformationMethods.GetUserName(format) ?? "<null>";
             Debug.WriteLine($"{format}: '{name}'");
         }
         catch (Exception e)
         {
             Debug.WriteLine($"{format}: FAILED- {e.Message}");
         }
     }
 }
Exemplo n.º 2
0
        public void GetTokenPrimaryGroupSid_ForCurrentProcess()
        {
            SID sid;

            using (var token = AuthorizationMethods.OpenProcessToken(AccessTokenRights.Read))
            {
                token.IsInvalid.Should().BeFalse();
                sid = AuthorizationMethods.GetTokenPrimaryGroupSid(token);
            }
            AuthorizationMethods.IsValidSid(ref sid).Should().BeTrue();

            AccountSidInformation info = AuthorizationMethods.LookupAccountSidLocal(sid);

            info.Name.Should().Be(SystemInformationMethods.GetUserName());
        }
Exemplo n.º 3
0
 public void GetSidForCreatedFile()
 {
     using (var cleaner = new TestFileCleaner())
     {
         using (var handle = FileMethods.CreateFile(cleaner.GetTestPath(), CreationDisposition.CreateNew))
         {
             handle.IsInvalid.Should().BeFalse();
             FileMethods.QueryOwner(handle, out SID sid);
             sid.IdentifierAuthority.Should().Be(SID_IDENTIFIER_AUTHORITY.NT);
             AccountSidInformation info = AuthorizationMethods.LookupAccountSidLocal(sid);
             info.Usage.Should().Be(SidNameUse.User);
             info.Name.Should().Be(SystemInformationMethods.GetUserName());
         }
     }
 }
Exemplo n.º 4
0
 public void GetUserNameDisplay()
 {
     SystemInformationMethods.GetUserName(EXTENDED_NAME_FORMAT.NameDisplay).Should().NotBeNullOrWhiteSpace();
 }
Exemplo n.º 5
0
 public void GetUserNameSam()
 {
     // Should be DOMAIN\user or COMPUTER\user
     SystemInformationMethods.GetUserName(EXTENDED_NAME_FORMAT.NameSamCompatible)
     .Should().Be($"{Environment.GetEnvironmentVariable("USERDOMAIN")}\\{Environment.GetEnvironmentVariable("USERNAME")}");
 }
Exemplo n.º 6
0
 public void GetCurrentUserName()
 {
     SystemInformationMethods.GetUserName().Should().Be(Environment.GetEnvironmentVariable("USERNAME"));
 }