1
0
mirror of https://github.com/bitwarden/server synced 2026-02-12 14:33:49 +00:00
Files
server/test/SharedWeb.Test/EncryptedStringSchemaFilterTest.cs
renovate[bot] 065d971dc4 [deps] Billing: Update swashbuckle-aspnetcore monorepo to v10 (major) (#6729)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Derek Nance <dnance@bitwarden.com>
2026-02-10 11:11:44 -05:00

61 lines
1.8 KiB
C#

using Bit.Core.Utilities;
using Bit.SharedWeb.Swagger;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace SharedWeb.Test;
public class EncryptedStringSchemaFilterTest
{
private class TestClass
{
[EncryptedString]
public string SecretKey { get; set; }
public string Username { get; set; }
[EncryptedString]
public int Wrong { get; set; }
}
[Fact]
public void AnnotatedStringSetsFormat()
{
var schema = new OpenApiSchema
{
Properties = new Dictionary<string, IOpenApiSchema> { { "secretKey", new OpenApiSchema() } }
};
var context = new SchemaFilterContext(typeof(TestClass), null, null, null);
var filter = new EncryptedStringSchemaFilter();
filter.Apply(schema, context);
Assert.Equal("x-enc-string", schema.Properties["secretKey"].Format);
}
[Fact]
public void NonAnnotatedStringIsIgnored()
{
var schema = new OpenApiSchema
{
Properties = new Dictionary<string, IOpenApiSchema> { { "username", new OpenApiSchema() } }
};
var context = new SchemaFilterContext(typeof(TestClass), null, null, null);
var filter = new EncryptedStringSchemaFilter();
filter.Apply(schema, context);
Assert.Null(schema.Properties["username"].Format);
}
[Fact]
public void AnnotatedWrongTypeIsIgnored()
{
var schema = new OpenApiSchema
{
Properties = new Dictionary<string, IOpenApiSchema> { { "wrong", new OpenApiSchema() } }
};
var context = new SchemaFilterContext(typeof(TestClass), null, null, null);
var filter = new EncryptedStringSchemaFilter();
filter.Apply(schema, context);
Assert.Null(schema.Properties["wrong"].Format);
}
}