-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathIEnvExtensionsTest.cs
More file actions
100 lines (83 loc) · 3.46 KB
/
IEnvExtensionsTest.cs
File metadata and controls
100 lines (83 loc) · 3.46 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
namespace AzureAuth.Test
{
using FluentAssertions;
using Microsoft.Authentication.AzureAuth;
using Microsoft.Authentication.MSALWrapper;
using Microsoft.Authentication.TestHelper;
using Microsoft.Extensions.Logging;
using Microsoft.Office.Lasso.Interfaces;
using Microsoft.Office.Lasso.Telemetry;
using Moq;
using NLog.Targets;
using NUnit.Framework;
public class IEnvExtensionsTest
{
private Mock<IEnv> envMock;
private ILogger logger;
private MemoryTarget logTarget;
[SetUp]
public void SetUp()
{
this.envMock = new Mock<IEnv>();
(this.logger, this.logTarget) = MemoryLogger.Create();
}
[TestCase("1", true)]
[TestCase("non-empty-string", false)]
[TestCase("true", false)]
[TestCase("", false)]
public void InteractiveAuth_IsDisabledOnCorextEnvVar(string corextNonInteractive, bool expected)
{
this.envMock.Setup(env => env.Get(It.IsAny<string>())).Returns((string)null);
this.envMock.Setup(e => e.Get("Corext_NonInteractive")).Returns(corextNonInteractive);
IEnvExtensions.InteractiveAuthDisabled(this.envMock.Object).Should().Be(expected);
}
[TestCase("1", true)]
[TestCase("non-empty-string", true)]
[TestCase("true", true)]
[TestCase("", false)]
public void InteractiveAuth_IsDisabledOnNoUserEnvVar(string noUser, bool expected)
{
this.envMock.Setup(env => env.Get(It.IsAny<string>())).Returns((string)null);
this.envMock.Setup(e => e.Get("AZUREAUTH_NO_USER")).Returns(noUser);
IEnvExtensions.InteractiveAuthDisabled(this.envMock.Object).Should().Be(expected);
}
[Test]
public void InteractiveAuth_IsEnabledIfEnvVarsAreNotSet()
{
this.envMock.Setup(env => env.Get(It.IsAny<string>())).Returns((string)null);
IEnvExtensions.InteractiveAuthDisabled(this.envMock.Object).Should().BeFalse();
}
[Test]
public void ReadAuthModeFromEnvOrSetDefault_ReturnsDefault_WhenEnvVarIsEmpty()
{
// Arrange
envMock.Setup(e => e.Get(It.IsAny<string>())).Returns(string.Empty);
// Act
var result = IEnvExtensions.ReadAuthModeFromEnvOrSetDefault(envMock.Object);
// Assert
result.Should().BeEquivalentTo(new[] { AuthMode.Default });
}
[Test]
public void ReadAuthModeFromEnvOrSetDefault_ReturnsParsedAuthModes_WhenEnvVarIsValid()
{
// Arrange
envMock.Setup(e => e.Get(It.IsAny<string>())).Returns("Web,DeviceCode");
// Act
var result = IEnvExtensions.ReadAuthModeFromEnvOrSetDefault(envMock.Object);
// Assert
result.Should().BeEquivalentTo(new[] { AuthMode.Web, AuthMode.DeviceCode });
}
[Test]
public void ReadAuthModeFromEnvOrSetDefault_ReturnsEmpty_WhenEnvVarIsInvalid()
{
// Arrange
envMock.Setup(e => e.Get(It.IsAny<string>())).Returns("InvalidMode");
// Act
var result = IEnvExtensions.ReadAuthModeFromEnvOrSetDefault(envMock.Object);
// Assert
result.Should().BeEmpty();
}
}
}