Skip to content

Commit a2e7ef2

Browse files
Copilotbaywet
andcommitted
Add tests for DeviceAuthorization serialization and update public API
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
1 parent 8ff3d23 commit a2e7ef2

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

test/Microsoft.OpenApi.Tests/Models/OpenApiOAuthFlowsTests.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ public class OpenApiOAuthFlowsTests
4848
}
4949
};
5050

51+
public static OpenApiOAuthFlows OAuthFlowsWithDeviceAuthorization = new()
52+
{
53+
DeviceAuthorization = new()
54+
{
55+
TokenUrl = new("http://example.com/token"),
56+
RefreshUrl = new("http://example.com/refresh"),
57+
Scopes = new Dictionary<string, string>
58+
{
59+
["scopeName1"] = "description1",
60+
["scopeName2"] = "description2"
61+
}
62+
}
63+
};
64+
5165
[Fact]
5266
public async Task SerializeBasicOAuthFlowsAsV3JsonWorks()
5367
{
@@ -139,5 +153,86 @@ public async Task SerializeOAuthFlowsWithMultipleFlowsAsV3JsonWorks()
139153
expected = expected.MakeLineBreaksEnvironmentNeutral();
140154
Assert.Equal(expected, actual);
141155
}
156+
157+
[Fact]
158+
public async Task SerializeOAuthFlowsWithDeviceAuthorizationAsV32JsonWorks()
159+
{
160+
// Arrange
161+
var expected =
162+
"""
163+
{
164+
"deviceAuthorization": {
165+
"tokenUrl": "http://example.com/token",
166+
"refreshUrl": "http://example.com/refresh",
167+
"scopes": {
168+
"scopeName1": "description1",
169+
"scopeName2": "description2"
170+
}
171+
}
172+
}
173+
""";
174+
175+
// Act
176+
var actual = await OAuthFlowsWithDeviceAuthorization.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_2);
177+
178+
// Assert
179+
actual = actual.MakeLineBreaksEnvironmentNeutral();
180+
expected = expected.MakeLineBreaksEnvironmentNeutral();
181+
Assert.Equal(expected, actual);
182+
}
183+
184+
[Fact]
185+
public async Task SerializeOAuthFlowsWithDeviceAuthorizationAsV31JsonWorks()
186+
{
187+
// Arrange
188+
var expected =
189+
"""
190+
{
191+
"x-oai-deviceAuthorization": {
192+
"tokenUrl": "http://example.com/token",
193+
"refreshUrl": "http://example.com/refresh",
194+
"scopes": {
195+
"scopeName1": "description1",
196+
"scopeName2": "description2"
197+
}
198+
}
199+
}
200+
""";
201+
202+
// Act
203+
var actual = await OAuthFlowsWithDeviceAuthorization.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1);
204+
205+
// Assert
206+
actual = actual.MakeLineBreaksEnvironmentNeutral();
207+
expected = expected.MakeLineBreaksEnvironmentNeutral();
208+
Assert.Equal(expected, actual);
209+
}
210+
211+
[Fact]
212+
public async Task SerializeOAuthFlowsWithDeviceAuthorizationAsV3JsonWorks()
213+
{
214+
// Arrange
215+
var expected =
216+
"""
217+
{
218+
"x-oai-deviceAuthorization": {
219+
"tokenUrl": "http://example.com/token",
220+
"refreshUrl": "http://example.com/refresh",
221+
"scopes": {
222+
"scopeName1": "description1",
223+
"scopeName2": "description2"
224+
}
225+
}
226+
}
227+
""";
228+
229+
// Act
230+
var actual = await OAuthFlowsWithDeviceAuthorization.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
231+
232+
// Assert
233+
actual = actual.MakeLineBreaksEnvironmentNeutral();
234+
expected = expected.MakeLineBreaksEnvironmentNeutral();
235+
Assert.Equal(expected, actual);
236+
}
142237
}
143238
}

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ namespace Microsoft.OpenApi
454454
public const string DependentRequired = "dependentRequired";
455455
public const string Deprecated = "deprecated";
456456
public const string Description = "description";
457+
public const string DeviceAuthorization = "deviceAuthorization";
457458
public const string Discriminator = "discriminator";
458459
public const string DollarRef = "$ref";
459460
public const string DollarSchema = "$schema";
@@ -927,6 +928,7 @@ namespace Microsoft.OpenApi
927928
public OpenApiOAuthFlows(Microsoft.OpenApi.OpenApiOAuthFlows oAuthFlows) { }
928929
public Microsoft.OpenApi.OpenApiOAuthFlow? AuthorizationCode { get; set; }
929930
public Microsoft.OpenApi.OpenApiOAuthFlow? ClientCredentials { get; set; }
931+
public Microsoft.OpenApi.OpenApiOAuthFlow? DeviceAuthorization { get; set; }
930932
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.IOpenApiExtension>? Extensions { get; set; }
931933
public Microsoft.OpenApi.OpenApiOAuthFlow? Implicit { get; set; }
932934
public Microsoft.OpenApi.OpenApiOAuthFlow? Password { get; set; }

0 commit comments

Comments
 (0)