-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
NTAccount.cs
49 lines (43 loc) · 1.39 KB
/
NTAccount.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.ComponentModel;
using Xunit;
namespace System.Security.Principal.Windows.Tests
{
public class NTAccountTest
{
[Fact]
public void Translate_Fail()
{
var nta = new NTAccount(Guid.NewGuid().ToString("N"));
try
{
nta.Translate(typeof(SecurityIdentifier));
}
catch (Exception e)
{
Asserts(e);
}
try
{
nta.Translate(typeof(SecurityIdentifier));
}
catch (Exception e)
{
Asserts(e);
}
return;
// Test assertions
void Asserts(Exception exception)
{
// If machine is in a domain but off line throws Win32Exception
Assert.True(exception is IdentityNotMappedException || exception is Win32Exception);
if (exception is Win32Exception win32Exception)
{
// ERROR_TRUSTED_RELATIONSHIP_FAILURE: The trust relationship between this workstation and the primary domain failed.
Assert.Equal(1789, win32Exception.NativeErrorCode);
}
}
}
}
}