-
Notifications
You must be signed in to change notification settings - Fork 12
Refactor tests #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Refactor tests #29
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ca1ff94
chore: Move tests to root.
peombwa 24aeef5
chore: Update solution.
peombwa 55e564b
- Adds verification tokens to OpenAI manifest auth
peombwa 29a3390
chore: Fix code smells.
peombwa a9ab5ad
chore: Remove empty statement.
peombwa fa21e6a
Merge branch 'main' into po/refactorTests
peombwa 8d373a0
- refactor BaseManifestAuth class.
peombwa 52a56f4
chore: Adds missing coverlet.msbuild
peombwa 653400a
- Adds OpenAI Plugin manifest validation
peombwa 05a9949
chore: Simplify OpenAIPluginManifest constructor.
peombwa 687f1d3
chore: Adds tests for ParseHelpers.
peombwa 36189d1
chore: Use ThrowIfNull for validating null objects.
peombwa ff2841e
chore: Remove explicit caller argument info on ThrowIfNull.
peombwa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using Microsoft.OpenApi.ApiManifest.OpenAI.Auth; | ||
| using System.Text.Json; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
baywet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public abstract class BaseManifestAuth | ||
baywet marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| public string? Type { get; set; } | ||
| public string? Instructions { get; set; } | ||
|
|
||
| public static BaseManifestAuth? Load(JsonElement value) | ||
| { | ||
| BaseManifestAuth? auth = null; | ||
|
|
||
| switch (value.GetProperty("type").GetString()) | ||
peombwa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| case "none": | ||
| auth = new ManifestNoAuth(); | ||
| ParsingHelpers.ParseMap(value, (ManifestNoAuth)auth, ManifestNoAuth.handlers); | ||
| break; | ||
| case "user_http": | ||
| var authorizationType = value.GetProperty("authorization_type").GetString(); | ||
| auth = new ManifestUserHttpAuth(authorizationType); | ||
| ParsingHelpers.ParseMap(value, (ManifestUserHttpAuth)auth, ManifestUserHttpAuth.handlers); | ||
| break; | ||
| case "service_http": | ||
| var verificationTokens = value.GetProperty("verification_tokens"); | ||
| auth = new ManifestServiceHttpAuth(VerificationTokens.Load(verificationTokens)); | ||
| ParsingHelpers.ParseMap(value, (ManifestServiceHttpAuth)auth, ManifestServiceHttpAuth.handlers); | ||
| break; | ||
| case "oauth": | ||
| auth = new ManifestOAuthAuth(); | ||
| ParsingHelpers.ParseMap(value, (ManifestOAuthAuth)auth, ManifestOAuthAuth.handlers); | ||
| break; | ||
| } | ||
|
|
||
| return auth; | ||
| } | ||
|
|
||
| // Create handlers FixedFieldMap for ManifestAuth | ||
|
|
||
| public virtual void Write(Utf8JsonWriter writer) { } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System.Text.Json; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
|
||
| public class ManifestNoAuth : BaseManifestAuth | ||
| { | ||
| public ManifestNoAuth() | ||
| { | ||
| Type = "none"; | ||
| } | ||
|
|
||
| internal static readonly FixedFieldMap<ManifestNoAuth> handlers = new() | ||
| { | ||
| { "type", (o,v) => {o.Type = v.GetString(); } }, | ||
peombwa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
| }; | ||
|
|
||
| public override void Write(Utf8JsonWriter writer) | ||
| { | ||
| writer.WriteStartObject(); | ||
| writer.WriteString("type", Type); | ||
| if (Instructions != null) writer.WriteString("instructions", Instructions); | ||
| writer.WriteEndObject(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using Microsoft.OpenApi.ApiManifest.OpenAI.Auth; | ||
| using System.Text.Json; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
|
||
| public class ManifestOAuthAuth : BaseManifestAuth | ||
| { | ||
| public string? ClientUrl { get; set; } | ||
| public string? Scope { get; set; } | ||
| public string? AuthorizationUrl { get; set; } | ||
| public string? AuthorizationContentType { get; set; } | ||
| public VerificationTokens VerificationTokens { get; set; } = new VerificationTokens(); | ||
|
|
||
| public ManifestOAuthAuth() | ||
| { | ||
| Type = "oauth"; | ||
| } | ||
| internal static readonly FixedFieldMap<ManifestOAuthAuth> handlers = new() | ||
| { | ||
| { "type", (o,v) => {o.Type = v.GetString(); } }, | ||
| { "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
| { "client_url", (o,v) => {o.ClientUrl = v.GetString(); } }, | ||
| { "scope", (o,v) => {o.Scope = v.GetString(); } }, | ||
| { "authorization_url", (o,v) => {o.AuthorizationUrl = v.GetString(); } }, | ||
| { "authorization_content_type", (o,v) => {o.AuthorizationContentType = v.GetString(); } }, | ||
| { "verification_tokens", (o,v) => { o.VerificationTokens = VerificationTokens.Load(v); } }, | ||
| }; | ||
|
|
||
| public override void Write(Utf8JsonWriter writer) | ||
| { | ||
| writer.WriteStartObject(); | ||
| writer.WriteString("type", Type); | ||
|
|
||
| if (Instructions != null) writer.WriteString("instructions", Instructions); | ||
peombwa marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (ClientUrl != null) writer.WriteString("client_url", ClientUrl); | ||
| if (Scope != null) writer.WriteString("scope", Scope); | ||
| if (AuthorizationUrl != null) writer.WriteString("authorization_url", AuthorizationUrl); | ||
| if (AuthorizationContentType != null) writer.WriteString("authorization_content_type", AuthorizationContentType); | ||
| if (VerificationTokens.Any()) | ||
| { | ||
| writer.WritePropertyName("verification_tokens"); | ||
| VerificationTokens.Write(writer); | ||
| } | ||
| writer.WriteEndObject(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using Microsoft.OpenApi.ApiManifest.OpenAI.Auth; | ||
| using System.Text.Json; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
|
||
| public class ManifestServiceHttpAuth : BaseManifestAuth | ||
| { | ||
| public string? AuthorizationType { get; set; } | ||
| public VerificationTokens VerificationTokens { get; set; } | ||
| public ManifestServiceHttpAuth(VerificationTokens verificationTokens) | ||
| { | ||
| if (verificationTokens == null || !verificationTokens.Any()) | ||
| { | ||
| // Reference: https://platform.openai.com/docs/plugins/authentication/service-level | ||
| throw new ArgumentException($"{nameof(verificationTokens)} must be have at least one verification token."); | ||
| } | ||
| Type = "service_http"; | ||
| AuthorizationType = "bearer"; | ||
| VerificationTokens = verificationTokens; | ||
| } | ||
|
|
||
| internal static readonly FixedFieldMap<ManifestServiceHttpAuth> handlers = new() | ||
| { | ||
| { "type", (o,v) => {o.Type = v.GetString(); } }, | ||
| { "authorization_type", (o,v) => {o.AuthorizationType = v.GetString(); } }, | ||
| { "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
| { "verification_tokens", (o, v) => { o.VerificationTokens = VerificationTokens.Load(v); } } | ||
| }; | ||
|
|
||
| public override void Write(Utf8JsonWriter writer) | ||
| { | ||
| writer.WriteStartObject(); | ||
| writer.WriteString("type", Type); | ||
| writer.WriteString("authorization_type", AuthorizationType); | ||
| if (Instructions != null) writer.WriteString("instructions", Instructions); | ||
| writer.WritePropertyName("verification_tokens"); | ||
| VerificationTokens.Write(writer); | ||
| writer.WriteEndObject(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System.Text.Json; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.OpenAI; | ||
|
|
||
| public class ManifestUserHttpAuth : BaseManifestAuth | ||
| { | ||
| public string? AuthorizationType { get; set; } | ||
| public ManifestUserHttpAuth(string? authorizationType) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(authorizationType) || (authorizationType != "basic" && authorizationType != "bearer")) | ||
| { | ||
| // Reference: https://platform.openai.com/docs/plugins/authentication/user-level | ||
| throw new ArgumentException($"{nameof(authorizationType)} must be either 'basic' or 'bearer'."); | ||
| } | ||
| Type = "user_http"; | ||
| AuthorizationType = authorizationType; | ||
| } | ||
|
|
||
| internal static readonly FixedFieldMap<ManifestUserHttpAuth> handlers = new() | ||
| { | ||
| { "type", (o,v) => {o.Type = v.GetString(); } }, | ||
| { "authorization_type", (o,v) => {o.AuthorizationType = v.GetString(); } }, | ||
| { "instructions", (o,v) => {o.Instructions = v.GetString(); } }, | ||
| }; | ||
| public override void Write(Utf8JsonWriter writer) | ||
| { | ||
| writer.WriteStartObject(); | ||
| writer.WriteString("type", Type); | ||
| writer.WriteString("authorization_type", AuthorizationType); | ||
| if (Instructions != null) writer.WriteString("instructions", Instructions); | ||
| writer.WriteEndObject(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT license. | ||
|
|
||
| using System.Text.Json; | ||
|
|
||
| namespace Microsoft.OpenApi.ApiManifest.OpenAI.Auth; | ||
|
|
||
| public class VerificationTokens : Dictionary<string, string> | ||
| { | ||
| public VerificationTokens(IDictionary<string, string> dictionary) : base(dictionary, StringComparer.OrdinalIgnoreCase) { } | ||
| public VerificationTokens() : base(StringComparer.OrdinalIgnoreCase) { } | ||
|
|
||
| internal static VerificationTokens Load(JsonElement value) | ||
| { | ||
| return new VerificationTokens(ParsingHelpers.GetMapOfString(value)); | ||
| } | ||
|
|
||
| public void Write(Utf8JsonWriter writer) | ||
| { | ||
| writer.WriteStartObject(); | ||
| foreach (var verificationToken in this) | ||
| { | ||
| writer.WriteString(verificationToken.Key, verificationToken.Value); | ||
| } | ||
| writer.WriteEndObject(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.