microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
cg/sovereign-cloud-nextcore

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

core/test/Microsoft.Teams.Bot.Core.UnitTests/Hosting/CloudEnvironmentTests.cs

176lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Bot.Core.Hosting;
5
6namespace Microsoft.Teams.Bot.Core.UnitTests.Hosting;
7
8public class CloudEnvironmentTests
9{
10 [Fact]
11 public void Public_HasCorrectEndpoints()
12 {
13 var env = CloudEnvironment.Public;
14
15 Assert.Equal("https://login.microsoftonline.com", env.LoginEndpoint);
16 Assert.Equal("botframework.com", env.LoginTenant);
17 Assert.Equal("https://api.botframework.com/.default", env.BotScope);
18 Assert.Equal("https://token.botframework.com", env.TokenServiceUrl);
19 Assert.Equal("https://login.botframework.com/v1/.well-known/openidconfiguration", env.OpenIdMetadataUrl);
20 Assert.Equal("https://api.botframework.com", env.TokenIssuer);
21 Assert.Equal("https://graph.microsoft.com/.default", env.GraphScope);
22 }
23
24 [Fact]
25 public void USGov_HasCorrectEndpoints()
26 {
27 var env = CloudEnvironment.USGov;
28
29 Assert.Equal("https://login.microsoftonline.us", env.LoginEndpoint);
30 Assert.Equal("MicrosoftServices.onmicrosoft.us", env.LoginTenant);
31 Assert.Equal("https://api.botframework.us/.default", env.BotScope);
32 Assert.Equal("https://tokengcch.botframework.azure.us", env.TokenServiceUrl);
33 Assert.Equal("https://login.botframework.azure.us/v1/.well-known/openidconfiguration", env.OpenIdMetadataUrl);
34 Assert.Equal("https://api.botframework.us", env.TokenIssuer);
35 Assert.Equal("https://graph.microsoft.us/.default", env.GraphScope);
36 }
37
38 [Fact]
39 public void USGovDoD_HasCorrectEndpoints()
40 {
41 var env = CloudEnvironment.USGovDoD;
42
43 Assert.Equal("https://login.microsoftonline.us", env.LoginEndpoint);
44 Assert.Equal("MicrosoftServices.onmicrosoft.us", env.LoginTenant);
45 Assert.Equal("https://api.botframework.us/.default", env.BotScope);
46 Assert.Equal("https://apiDoD.botframework.azure.us", env.TokenServiceUrl);
47 Assert.Equal("https://api.botframework.us", env.TokenIssuer);
48 Assert.Equal("https://dod-graph.microsoft.us/.default", env.GraphScope);
49 }
50
51 [Fact]
52 public void China_HasCorrectEndpoints()
53 {
54 var env = CloudEnvironment.China;
55
56 Assert.Equal("https://login.partner.microsoftonline.cn", env.LoginEndpoint);
57 Assert.Equal("microsoftservices.partner.onmschina.cn", env.LoginTenant);
58 Assert.Equal("https://api.botframework.azure.cn/.default", env.BotScope);
59 Assert.Equal("https://token.botframework.azure.cn", env.TokenServiceUrl);
60 Assert.Equal("https://api.botframework.azure.cn", env.TokenIssuer);
61 Assert.Equal("https://microsoftgraph.chinacloudapi.cn/.default", env.GraphScope);
62 }
63
64 [Theory]
65 [InlineData("Public", "https://login.microsoftonline.com")]
66 [InlineData("public", "https://login.microsoftonline.com")]
67 [InlineData("PUBLIC", "https://login.microsoftonline.com")]
68 [InlineData("USGov", "https://login.microsoftonline.us")]
69 [InlineData("usgov", "https://login.microsoftonline.us")]
70 [InlineData("USGovDoD", "https://login.microsoftonline.us")]
71 [InlineData("usgovdod", "https://login.microsoftonline.us")]
72 [InlineData("China", "https://login.partner.microsoftonline.cn")]
73 [InlineData("china", "https://login.partner.microsoftonline.cn")]
74 public void FromName_ResolvesCorrectly(string name, string expectedLoginEndpoint)
75 {
76 var env = CloudEnvironment.FromName(name);
77 Assert.Equal(expectedLoginEndpoint, env.LoginEndpoint);
78 }
79
80 [Fact]
81 public void FromName_ReturnsStaticInstances()
82 {
83 Assert.Same(CloudEnvironment.Public, CloudEnvironment.FromName("Public"));
84 Assert.Same(CloudEnvironment.USGov, CloudEnvironment.FromName("USGov"));
85 Assert.Same(CloudEnvironment.USGovDoD, CloudEnvironment.FromName("USGovDoD"));
86 Assert.Same(CloudEnvironment.China, CloudEnvironment.FromName("China"));
87 }
88
89 [Theory]
90 [InlineData("invalid")]
91 [InlineData("Azure")]
92 public void FromName_ThrowsForUnknownName(string name)
93 {
94 Assert.Throws<ArgumentException>(() => CloudEnvironment.FromName(name));
95 }
96
97 [Theory]
98 [InlineData("")]
99 [InlineData(" ")]
100 public void FromName_ThrowsForEmptyOrWhitespace(string name)
101 {
102 ArgumentException ex = Assert.Throws<ArgumentException>(() => CloudEnvironment.FromName(name));
103 Assert.Contains("empty or whitespace", ex.Message);
104 }
105
106 [Fact]
107 public void FromName_ThrowsForNull()
108 {
109 Assert.Throws<ArgumentNullException>(() => CloudEnvironment.FromName(null!));
110 }
111
112 [Fact]
113 public void Constructor_TrimsTrailingSlashOnLoginEndpointAndTokenServiceUrl()
114 {
115 var env = new CloudEnvironment(
116 loginEndpoint: "https://example.com/",
117 loginTenant: "tenant",
118 botScope: "scope",
119 tokenServiceUrl: "https://token.example.com/",
120 openIdMetadataUrl: "https://oidc.example.com",
121 tokenIssuer: "issuer",
122 graphScope: "graph");
123
124 Assert.Equal("https://example.com", env.LoginEndpoint);
125 Assert.Equal("https://token.example.com", env.TokenServiceUrl);
126 }
127
128 [Fact]
129 public void WithOverrides_AllNulls_ReturnsSameInstance()
130 {
131 var env = CloudEnvironment.Public;
132
133 var result = env.WithOverrides();
134
135 Assert.Same(env, result);
136 }
137
138 [Fact]
139 public void WithOverrides_SingleOverride_ReplacesOnlyThatProperty()
140 {
141 var env = CloudEnvironment.Public;
142
143 var result = env.WithOverrides(tokenIssuer: "https://custom.issuer");
144
145 Assert.NotSame(env, result);
146 Assert.Equal("https://custom.issuer", result.TokenIssuer);
147 Assert.Equal(env.LoginEndpoint, result.LoginEndpoint);
148 Assert.Equal(env.BotScope, result.BotScope);
149 Assert.Equal(env.TokenServiceUrl, result.TokenServiceUrl);
150 Assert.Equal(env.OpenIdMetadataUrl, result.OpenIdMetadataUrl);
151 Assert.Equal(env.GraphScope, result.GraphScope);
152 }
153
154 [Fact]
155 public void WithOverrides_AllOverrides_ReplacesAllProperties()
156 {
157 var env = CloudEnvironment.Public;
158
159 var result = env.WithOverrides(
160 loginEndpoint: "https://a",
161 loginTenant: "b",
162 botScope: "c",
163 tokenServiceUrl: "https://d",
164 openIdMetadataUrl: "e",
165 tokenIssuer: "f",
166 graphScope: "g");
167
168 Assert.Equal("https://a", result.LoginEndpoint);
169 Assert.Equal("b", result.LoginTenant);
170 Assert.Equal("c", result.BotScope);
171 Assert.Equal("https://d", result.TokenServiceUrl);
172 Assert.Equal("e", result.OpenIdMetadataUrl);
173 Assert.Equal("f", result.TokenIssuer);
174 Assert.Equal("g", result.GraphScope);
175 }
176}
177