mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
[PM-2196] Improvements to the Swagger generator (#2914)
* Swagger fixes Co-Authored-By: Oscar Hinton <Hinton@users.noreply.github.com> * Make Response Models return Guids instead of strings * Change strings into guids in ScimApplicationFactory --------- Co-authored-by: Oscar Hinton <Hinton@users.noreply.github.com>
This commit is contained in:
@ -19,18 +19,18 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
{
|
||||
public readonly new TestServer Server;
|
||||
|
||||
public const string TestUserId1 = "2e8173db-8e8d-4de1-ac38-91b15c6d8dcb";
|
||||
public const string TestUserId2 = "b57846fc-0e94-4c93-9de5-9d0389eeadfb";
|
||||
public const string TestUserId3 = "20713eb8-d0c5-4655-b855-1a0f3472ccb5";
|
||||
public const string TestUserId4 = "cee613af-d0cb-4db9-ab9d-579bb120fd2a";
|
||||
public const string TestGroupId1 = "dcb232e8-761d-4152-a510-be2778d037cb";
|
||||
public const string TestGroupId2 = "562e5371-7020-40b6-b092-099ac66dbdf9";
|
||||
public const string TestGroupId3 = "362c2782-0f1f-4c86-95dd-edbdf7d6040b";
|
||||
public const string TestOrganizationId1 = "fb98e04f-0303-4914-9b37-a983943bf1ca";
|
||||
public const string TestOrganizationUserId1 = "5d421196-8c59-485b-8926-2d6d0101e05f";
|
||||
public const string TestOrganizationUserId2 = "3a63d520-0d84-4679-b887-13fe2058d53b";
|
||||
public const string TestOrganizationUserId3 = "be2f9045-e2b6-4173-ad44-4c69c3ea8140";
|
||||
public const string TestOrganizationUserId4 = "1f5689b7-e96e-4840-b0b1-eb3d5b5fd514";
|
||||
public static readonly Guid TestUserId1 = Guid.Parse("2e8173db-8e8d-4de1-ac38-91b15c6d8dcb");
|
||||
public static readonly Guid TestUserId2 = Guid.Parse("b57846fc-0e94-4c93-9de5-9d0389eeadfb");
|
||||
public static readonly Guid TestUserId3 = Guid.Parse("20713eb8-d0c5-4655-b855-1a0f3472ccb5");
|
||||
public static readonly Guid TestUserId4 = Guid.Parse("cee613af-d0cb-4db9-ab9d-579bb120fd2a");
|
||||
public static readonly Guid TestGroupId1 = Guid.Parse("dcb232e8-761d-4152-a510-be2778d037cb");
|
||||
public static readonly Guid TestGroupId2 = Guid.Parse("562e5371-7020-40b6-b092-099ac66dbdf9");
|
||||
public static readonly Guid TestGroupId3 = Guid.Parse("362c2782-0f1f-4c86-95dd-edbdf7d6040b");
|
||||
public static readonly Guid TestOrganizationId1 = Guid.Parse("fb98e04f-0303-4914-9b37-a983943bf1ca");
|
||||
public static readonly Guid TestOrganizationUserId1 = Guid.Parse("5d421196-8c59-485b-8926-2d6d0101e05f");
|
||||
public static readonly Guid TestOrganizationUserId2 = Guid.Parse("3a63d520-0d84-4679-b887-13fe2058d53b");
|
||||
public static readonly Guid TestOrganizationUserId3 = Guid.Parse("be2f9045-e2b6-4173-ad44-4c69c3ea8140");
|
||||
public static readonly Guid TestOrganizationUserId4 = Guid.Parse("1f5689b7-e96e-4840-b0b1-eb3d5b5fd514");
|
||||
|
||||
public ScimApplicationFactory()
|
||||
{
|
||||
@ -60,12 +60,12 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
Server = webApplicationFactory.Server;
|
||||
}
|
||||
|
||||
public async Task<HttpContext> GroupsGetAsync(string organizationId, string id)
|
||||
public async Task<HttpContext> GroupsGetAsync(Guid organizationId, Guid id)
|
||||
{
|
||||
return await Server.GetAsync($"/v2/{organizationId}/groups/{id}");
|
||||
}
|
||||
|
||||
public async Task<HttpContext> GroupsGetListAsync(string organizationId, string filter, int? count, int? startIndex)
|
||||
public async Task<HttpContext> GroupsGetListAsync(Guid organizationId, string filter, int? count, int? startIndex)
|
||||
{
|
||||
var queryString = new QueryString("?");
|
||||
|
||||
@ -87,32 +87,32 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
return await Server.GetAsync($"/v2/{organizationId}/groups", httpContext => httpContext.Request.QueryString = queryString);
|
||||
}
|
||||
|
||||
public async Task<HttpContext> GroupsPostAsync(string organizationId, ScimGroupRequestModel model)
|
||||
public async Task<HttpContext> GroupsPostAsync(Guid organizationId, ScimGroupRequestModel model)
|
||||
{
|
||||
return await Server.PostAsync($"/v2/{organizationId}/groups", GetStringContent(model), httpContext => httpContext.Request.Headers.Add(HeaderNames.UserAgent, "Okta"));
|
||||
}
|
||||
|
||||
public async Task<HttpContext> GroupsPutAsync(string organizationId, string id, ScimGroupRequestModel model)
|
||||
public async Task<HttpContext> GroupsPutAsync(Guid organizationId, Guid id, ScimGroupRequestModel model)
|
||||
{
|
||||
return await Server.PutAsync($"/v2/{organizationId}/groups/{id}", GetStringContent(model), httpContext => httpContext.Request.Headers.Add(HeaderNames.UserAgent, "Okta"));
|
||||
}
|
||||
|
||||
public async Task<HttpContext> GroupsPatchAsync(string organizationId, string id, ScimPatchModel model)
|
||||
public async Task<HttpContext> GroupsPatchAsync(Guid organizationId, Guid id, ScimPatchModel model)
|
||||
{
|
||||
return await Server.PatchAsync($"/v2/{organizationId}/groups/{id}", GetStringContent(model));
|
||||
}
|
||||
|
||||
public async Task<HttpContext> GroupsDeleteAsync(string organizationId, string id)
|
||||
public async Task<HttpContext> GroupsDeleteAsync(Guid organizationId, Guid id)
|
||||
{
|
||||
return await Server.DeleteAsync($"/v2/{organizationId}/groups/{id}", null);
|
||||
}
|
||||
|
||||
public async Task<HttpContext> UsersGetAsync(string organizationId, string id)
|
||||
public async Task<HttpContext> UsersGetAsync(Guid organizationId, Guid id)
|
||||
{
|
||||
return await Server.GetAsync($"/v2/{organizationId}/users/{id}");
|
||||
}
|
||||
|
||||
public async Task<HttpContext> UsersGetListAsync(string organizationId, string filter, int? count, int? startIndex)
|
||||
public async Task<HttpContext> UsersGetListAsync(Guid organizationId, string filter, int? count, int? startIndex)
|
||||
{
|
||||
var queryString = new QueryString("?");
|
||||
|
||||
@ -134,22 +134,22 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
return await Server.GetAsync($"/v2/{organizationId}/users", httpContext => httpContext.Request.QueryString = queryString);
|
||||
}
|
||||
|
||||
public async Task<HttpContext> UsersPostAsync(string organizationId, ScimUserRequestModel model)
|
||||
public async Task<HttpContext> UsersPostAsync(Guid organizationId, ScimUserRequestModel model)
|
||||
{
|
||||
return await Server.PostAsync($"/v2/{organizationId}/users", GetStringContent(model));
|
||||
}
|
||||
|
||||
public async Task<HttpContext> UsersPutAsync(string organizationId, string id, ScimUserRequestModel model)
|
||||
public async Task<HttpContext> UsersPutAsync(Guid organizationId, Guid id, ScimUserRequestModel model)
|
||||
{
|
||||
return await Server.PutAsync($"/v2/{organizationId}/users/{id}", GetStringContent(model));
|
||||
}
|
||||
|
||||
public async Task<HttpContext> UsersPatchAsync(string organizationId, string id, ScimPatchModel model)
|
||||
public async Task<HttpContext> UsersPatchAsync(Guid organizationId, Guid id, ScimPatchModel model)
|
||||
{
|
||||
return await Server.PatchAsync($"/v2/{organizationId}/users/{id}", GetStringContent(model));
|
||||
}
|
||||
|
||||
public async Task<HttpContext> UsersDeleteAsync(string organizationId, string id, ScimUserRequestModel model)
|
||||
public async Task<HttpContext> UsersDeleteAsync(Guid organizationId, Guid id, ScimUserRequestModel model)
|
||||
{
|
||||
return await Server.DeleteAsync($"/v2/{organizationId}/users/{id}", GetStringContent(model));
|
||||
}
|
||||
@ -179,10 +179,10 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
{
|
||||
return new List<Infrastructure.EntityFramework.Models.User>()
|
||||
{
|
||||
new Infrastructure.EntityFramework.Models.User { Id = Guid.Parse(TestUserId1), Name = "Test User 1", ApiKey = "", Email = "user1@example.com", SecurityStamp = "" },
|
||||
new Infrastructure.EntityFramework.Models.User { Id = Guid.Parse(TestUserId2), Name = "Test User 2", ApiKey = "", Email = "user2@example.com", SecurityStamp = "" },
|
||||
new Infrastructure.EntityFramework.Models.User { Id = Guid.Parse(TestUserId3), Name = "Test User 3", ApiKey = "", Email = "user3@example.com", SecurityStamp = "" },
|
||||
new Infrastructure.EntityFramework.Models.User { Id = Guid.Parse(TestUserId4), Name = "Test User 4", ApiKey = "", Email = "user4@example.com", SecurityStamp = "" },
|
||||
new Infrastructure.EntityFramework.Models.User { Id = TestUserId1, Name = "Test User 1", ApiKey = "", Email = "user1@example.com", SecurityStamp = "" },
|
||||
new Infrastructure.EntityFramework.Models.User { Id = TestUserId2, Name = "Test User 2", ApiKey = "", Email = "user2@example.com", SecurityStamp = "" },
|
||||
new Infrastructure.EntityFramework.Models.User { Id = TestUserId3, Name = "Test User 3", ApiKey = "", Email = "user3@example.com", SecurityStamp = "" },
|
||||
new Infrastructure.EntityFramework.Models.User { Id = TestUserId4, Name = "Test User 4", ApiKey = "", Email = "user4@example.com", SecurityStamp = "" },
|
||||
};
|
||||
}
|
||||
|
||||
@ -190,9 +190,9 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
{
|
||||
return new List<Infrastructure.EntityFramework.Models.Group>()
|
||||
{
|
||||
new Infrastructure.EntityFramework.Models.Group { Id = Guid.Parse(TestGroupId1), OrganizationId = Guid.Parse(TestOrganizationId1), Name = "Test Group 1", ExternalId = "A" },
|
||||
new Infrastructure.EntityFramework.Models.Group { Id = Guid.Parse(TestGroupId2), OrganizationId = Guid.Parse(TestOrganizationId1), Name = "Test Group 2", ExternalId = "B" },
|
||||
new Infrastructure.EntityFramework.Models.Group { Id = Guid.Parse(TestGroupId3), OrganizationId = Guid.Parse(TestOrganizationId1), Name = "Test Group 3", ExternalId = "C" }
|
||||
new Infrastructure.EntityFramework.Models.Group { Id = TestGroupId1, OrganizationId = TestOrganizationId1, Name = "Test Group 1", ExternalId = "A" },
|
||||
new Infrastructure.EntityFramework.Models.Group { Id = TestGroupId2, OrganizationId = TestOrganizationId1, Name = "Test Group 2", ExternalId = "B" },
|
||||
new Infrastructure.EntityFramework.Models.Group { Id = TestGroupId3, OrganizationId = TestOrganizationId1, Name = "Test Group 3", ExternalId = "C" }
|
||||
};
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
{
|
||||
return new List<Infrastructure.EntityFramework.Models.Organization>()
|
||||
{
|
||||
new Infrastructure.EntityFramework.Models.Organization { Id = Guid.Parse(TestOrganizationId1), Name = "Test Organization 1", UseGroups = true }
|
||||
new Infrastructure.EntityFramework.Models.Organization { Id = TestOrganizationId1, Name = "Test Organization 1", UseGroups = true }
|
||||
};
|
||||
}
|
||||
|
||||
@ -208,10 +208,10 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
{
|
||||
return new List<Infrastructure.EntityFramework.Models.OrganizationUser>()
|
||||
{
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = Guid.Parse(TestOrganizationUserId1), OrganizationId = Guid.Parse(TestOrganizationId1), UserId = Guid.Parse(TestUserId1), Status = Core.Enums.OrganizationUserStatusType.Confirmed, ExternalId = "UA", Email = "user1@example.com" },
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = Guid.Parse(TestOrganizationUserId2), OrganizationId = Guid.Parse(TestOrganizationId1), UserId = Guid.Parse(TestUserId2), Status = Core.Enums.OrganizationUserStatusType.Confirmed, ExternalId = "UB", Email = "user2@example.com" },
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = Guid.Parse(TestOrganizationUserId3), OrganizationId = Guid.Parse(TestOrganizationId1), UserId = Guid.Parse(TestUserId3), Status = Core.Enums.OrganizationUserStatusType.Revoked, ExternalId = "UC", Email = "user3@example.com" },
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = Guid.Parse(TestOrganizationUserId4), OrganizationId = Guid.Parse(TestOrganizationId1), UserId = Guid.Parse(TestUserId4), Status = Core.Enums.OrganizationUserStatusType.Confirmed, ExternalId = "UD", Email = "user4@example.com" },
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = TestOrganizationUserId1, OrganizationId = TestOrganizationId1, UserId = TestUserId1, Status = Core.Enums.OrganizationUserStatusType.Confirmed, ExternalId = "UA", Email = "user1@example.com" },
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = TestOrganizationUserId2, OrganizationId = TestOrganizationId1, UserId = TestUserId2, Status = Core.Enums.OrganizationUserStatusType.Confirmed, ExternalId = "UB", Email = "user2@example.com" },
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = TestOrganizationUserId3, OrganizationId = TestOrganizationId1, UserId = TestUserId3, Status = Core.Enums.OrganizationUserStatusType.Revoked, ExternalId = "UC", Email = "user3@example.com" },
|
||||
new Infrastructure.EntityFramework.Models.OrganizationUser { Id = TestOrganizationUserId4, OrganizationId = TestOrganizationId1, UserId = TestUserId4, Status = Core.Enums.OrganizationUserStatusType.Confirmed, ExternalId = "UD", Email = "user4@example.com" },
|
||||
};
|
||||
}
|
||||
|
||||
@ -219,8 +219,8 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
{
|
||||
return new List<Infrastructure.EntityFramework.Models.GroupUser>()
|
||||
{
|
||||
new Infrastructure.EntityFramework.Models.GroupUser { GroupId = Guid.Parse(TestGroupId1), OrganizationUserId = Guid.Parse(TestOrganizationUserId1) },
|
||||
new Infrastructure.EntityFramework.Models.GroupUser { GroupId = Guid.Parse(TestGroupId1), OrganizationUserId = Guid.Parse(TestOrganizationUserId4) }
|
||||
new Infrastructure.EntityFramework.Models.GroupUser { GroupId = TestGroupId1, OrganizationUserId = TestOrganizationUserId1 },
|
||||
new Infrastructure.EntityFramework.Models.GroupUser { GroupId = TestGroupId1, OrganizationUserId = TestOrganizationUserId4 }
|
||||
};
|
||||
}
|
||||
|
||||
@ -239,7 +239,7 @@ public class ScimApplicationFactory : WebApplicationFactoryBase<Startup>
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(ClaimTypes.Name, "Test user"),
|
||||
new Claim("orgadmin", TestOrganizationId1)
|
||||
new Claim("orgadmin", TestOrganizationId1.ToString())
|
||||
};
|
||||
var identity = new ClaimsIdentity(claims, "Test");
|
||||
var principal = new ClaimsPrincipal(identity);
|
||||
|
Reference in New Issue
Block a user