Skip to content

Commit

Permalink
Merge branch 'master' into feature/sm-billing
Browse files Browse the repository at this point in the history
  • Loading branch information
cturnbull-bitwarden committed Jul 14, 2023
2 parents 99b598a + 4f87e4e commit a79a523
Show file tree
Hide file tree
Showing 43 changed files with 213 additions and 218 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

# DevOps for Actions and other workflow changes.
.github/workflows @bitwarden/dept-devops

## Auth team files ##
**/Auth @bitwarden/team-auth-dev
bitwarden_license/src/Sso @bitwarden/team-auth-dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: 'Run stale action'
uses: actions/stale@f7176fd3007623b69d27091f9b9d4ab7995f0a06 # v5.2.1
uses: actions/stale@1160a2240286f5da8ec72b1c0816ce2481aabf84 # v8.0.0
with:
stale-issue-label: 'needs-reply'
stale-pr-label: 'needs-changes'
Expand Down
4 changes: 2 additions & 2 deletions bitwarden_license/src/Scim/Models/ScimGroupResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public ScimGroupResponseModel()
public ScimGroupResponseModel(Group group)
: this()
{
Id = group.Id.ToString();
Id = group.Id;
DisplayName = group.Name;
ExternalId = group.ExternalId;
Meta.Created = group.CreationDate;
Meta.LastModified = group.RevisionDate;
}

public string Id { get; set; }
public Guid Id { get; set; }
public ScimMetaModel Meta { get; private set; }
}
4 changes: 2 additions & 2 deletions bitwarden_license/src/Scim/Models/ScimUserResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public ScimUserResponseModel()
public ScimUserResponseModel(OrganizationUserUserDetails orgUser)
: this()
{
Id = orgUser.Id.ToString();
Id = orgUser.Id;
ExternalId = orgUser.ExternalId;
UserName = orgUser.Email;
DisplayName = orgUser.Name;
Expand All @@ -23,6 +23,6 @@ public ScimUserResponseModel(OrganizationUserUserDetails orgUser)
Active = orgUser.Status != Core.Enums.OrganizationUserStatusType.Revoked;
}

public string Id { get; set; }
public Guid Id { get; set; }
public ScimMetaModel Meta { get; private set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public async Task Get_Success()
public async Task Get_NotFound()
{
var organizationId = ScimApplicationFactory.TestOrganizationId1;
var groupId = Guid.NewGuid().ToString();
var groupId = Guid.NewGuid();
var expectedResponse = new ScimErrorResponseModel
{
Status = StatusCodes.Status404NotFound,
Expand Down Expand Up @@ -214,7 +214,7 @@ public async Task Post_Success()
ExternalId = externalId.ToString(),
Members = new List<ScimGroupRequestModel.GroupMembersModel>
{
new ScimGroupRequestModel.GroupMembersModel { Display = "[email protected]", Value = ScimApplicationFactory.TestOrganizationUserId1 }
new ScimGroupRequestModel.GroupMembersModel { Display = "[email protected]", Value = ScimApplicationFactory.TestOrganizationUserId1.ToString() }
},
Schemas = new List<string>() { ScimConstants.Scim2SchemaGroup }
};
Expand All @@ -234,14 +234,13 @@ public async Task Post_Success()

var responseModel = JsonSerializer.Deserialize<ScimGroupResponseModel>(context.Response.Body, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
AssertHelper.AssertPropertyEqual(expectedResponse, responseModel, "Id");
Assert.NotNull(responseModel.Id);

var databaseContext = _factory.GetDatabaseContext();
Assert.Equal(_initialGroupCount + 1, databaseContext.Groups.Count());
Assert.True(databaseContext.Groups.Any(g => g.Name == displayName && g.ExternalId == externalId));

Assert.Equal(_initialGroupUsersCount + 1, databaseContext.GroupUsers.Count());
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId.ToString() == responseModel.Id && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId1));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId == responseModel.Id && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId1));
}

[Theory]
Expand Down Expand Up @@ -297,8 +296,8 @@ public async Task Put_ChangeNameAndMembers_Success()
ExternalId = "A",
Members = new List<ScimGroupRequestModel.GroupMembersModel>
{
new ScimGroupRequestModel.GroupMembersModel { Display = "[email protected]", Value = ScimApplicationFactory.TestOrganizationUserId2 },
new ScimGroupRequestModel.GroupMembersModel { Display = "[email protected]", Value = ScimApplicationFactory.TestOrganizationUserId3 }
new ScimGroupRequestModel.GroupMembersModel { Display = "[email protected]", Value = ScimApplicationFactory.TestOrganizationUserId2.ToString() },
new ScimGroupRequestModel.GroupMembersModel { Display = "[email protected]", Value = ScimApplicationFactory.TestOrganizationUserId3.ToString() }
},
Schemas = new List<string>() { ScimConstants.Scim2SchemaGroup }
};
Expand All @@ -318,20 +317,20 @@ public async Task Put_ChangeNameAndMembers_Success()
AssertHelper.AssertPropertyEqual(expectedResponse, responseModel);

var databaseContext = _factory.GetDatabaseContext();
var firstGroup = databaseContext.Groups.FirstOrDefault(g => g.Id.ToString() == groupId);
var firstGroup = databaseContext.Groups.FirstOrDefault(g => g.Id == groupId);
Assert.Equal(newGroupName, firstGroup.Name);

Assert.Equal(2, databaseContext.GroupUsers.Count(gu => gu.GroupId.ToString() == groupId));
Assert.NotNull(databaseContext.GroupUsers.FirstOrDefault(gu => gu.GroupId.ToString() == groupId && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId2));
Assert.NotNull(databaseContext.GroupUsers.FirstOrDefault(gu => gu.GroupId.ToString() == groupId && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId3));
Assert.Equal(2, databaseContext.GroupUsers.Count(gu => gu.GroupId == groupId));
Assert.NotNull(databaseContext.GroupUsers.FirstOrDefault(gu => gu.GroupId == groupId && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId2));
Assert.NotNull(databaseContext.GroupUsers.FirstOrDefault(gu => gu.GroupId == groupId && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId3));
}

[Fact]
public async Task Put_NotFound()
{
var newGroupName = "Test Group 1 New Name";
var organizationId = ScimApplicationFactory.TestOrganizationId1;
var groupId = Guid.NewGuid().ToString();
var groupId = Guid.NewGuid();
var inputModel = new ScimGroupRequestModel
{
DisplayName = newGroupName,
Expand Down Expand Up @@ -378,12 +377,12 @@ public async Task Patch_ReplaceDisplayName_Success()
Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode);

var databaseContext = _factory.GetDatabaseContext();
var group = databaseContext.Groups.FirstOrDefault(g => g.Id.ToString() == groupId);
var group = databaseContext.Groups.FirstOrDefault(g => g.Id == groupId);
Assert.Equal(newDisplayName, group.Name);

Assert.Equal(_initialGroupUsersCount, databaseContext.GroupUsers.Count());
Assert.True(databaseContext.GroupUsers.Any(gu => gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId1));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId4));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId1));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId4));
}

[Fact]
Expand Down Expand Up @@ -414,7 +413,7 @@ public async Task Patch_ReplaceMembers_Success()

Assert.Equal(_initialGroupUsersCount - 1, databaseContext.GroupUsers.Count());
var groupUser = databaseContext.GroupUsers.FirstOrDefault();
Assert.Equal(ScimApplicationFactory.TestOrganizationUserId2, groupUser.OrganizationUserId.ToString());
Assert.Equal(ScimApplicationFactory.TestOrganizationUserId2, groupUser.OrganizationUserId);
}

[Fact]
Expand Down Expand Up @@ -442,9 +441,9 @@ public async Task Patch_AddSingleMember_Success()

var databaseContext = _factory.GetDatabaseContext();
Assert.Equal(_initialGroupUsersCount + 1, databaseContext.GroupUsers.Count());
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId.ToString() == groupId && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId1));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId.ToString() == groupId && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId2));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId.ToString() == groupId && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId4));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId == groupId && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId1));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId == groupId && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId2));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId == groupId && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId4));
}

[Fact]
Expand All @@ -471,8 +470,8 @@ public async Task Patch_AddListMembers_Success()
Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode);

var databaseContext = _factory.GetDatabaseContext();
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId.ToString() == groupId && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId2));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId.ToString() == groupId && gu.OrganizationUserId.ToString() == ScimApplicationFactory.TestOrganizationUserId3));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId == groupId && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId2));
Assert.True(databaseContext.GroupUsers.Any(gu => gu.GroupId == groupId && gu.OrganizationUserId == ScimApplicationFactory.TestOrganizationUserId3));
}

[Fact]
Expand Down Expand Up @@ -508,7 +507,7 @@ public async Task Patch_RemoveSingleMember_ReplaceDisplayName_Success()
Assert.Equal(_initialGroupUsersCount - 1, databaseContext.GroupUsers.Count());
Assert.Equal(_initialGroupCount, databaseContext.Groups.Count());

var group = databaseContext.Groups.FirstOrDefault(g => g.Id.ToString() == groupId);
var group = databaseContext.Groups.FirstOrDefault(g => g.Id == groupId);
Assert.Equal(newDisplayName, group.Name);
}

Expand Down Expand Up @@ -543,7 +542,7 @@ public async Task Patch_RemoveListMembers_Success()
public async Task Patch_NotFound()
{
var organizationId = ScimApplicationFactory.TestOrganizationId1;
var groupId = Guid.NewGuid().ToString();
var groupId = Guid.NewGuid();
var inputModel = new Models.ScimPatchModel
{
Operations = new List<ScimPatchModel.OperationModel>(),
Expand Down Expand Up @@ -576,14 +575,14 @@ public async Task Delete_Success()

var databaseContext = _factory.GetDatabaseContext();
Assert.Equal(_initialGroupCount - 1, databaseContext.Groups.Count());
Assert.True(databaseContext.Groups.FirstOrDefault(g => g.Id.ToString() == groupId) == null);
Assert.True(databaseContext.Groups.FirstOrDefault(g => g.Id == groupId) == null);
}

[Fact]
public async Task Delete_NotFound()
{
var organizationId = ScimApplicationFactory.TestOrganizationId1;
var groupId = Guid.NewGuid().ToString();
var groupId = Guid.NewGuid();
var expectedResponse = new ScimErrorResponseModel
{
Status = StatusCodes.Status404NotFound,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public async Task Get_Success()
[Fact]
public async Task Get_NotFound()
{
var organizationUserId = Guid.NewGuid().ToString();
var organizationUserId = Guid.NewGuid();
var expectedResponse = new ScimErrorResponseModel
{
Status = StatusCodes.Status404NotFound,
Expand Down Expand Up @@ -274,7 +274,6 @@ public async Task Post_Success()

var responseModel = JsonSerializer.Deserialize<ScimUserResponseModel>(context.Response.Body, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
AssertHelper.AssertPropertyEqual(expectedResponse, responseModel, "Id");
Assert.NotNull(responseModel.Id);

var databaseContext = _factory.GetDatabaseContext();
Assert.Equal(_initialUserCount + 1, databaseContext.OrganizationUsers.Count());
Expand Down Expand Up @@ -373,7 +372,7 @@ public async Task Put_RevokeUser_Success()
AssertHelper.AssertPropertyEqual(expectedResponse, responseModel);

var databaseContext = _factory.GetDatabaseContext();
var revokedUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id.ToString() == organizationUserId);
var revokedUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id == organizationUserId);
Assert.Equal(OrganizationUserStatusType.Revoked, revokedUser.Status);
}

Expand Down Expand Up @@ -408,7 +407,7 @@ public async Task Put_RestoreUser_Success()
AssertHelper.AssertPropertyEqual(expectedResponse, responseModel);

var databaseContext = _factory.GetDatabaseContext();
var revokedUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id.ToString() == organizationUserId);
var revokedUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id == organizationUserId);
Assert.NotEqual(OrganizationUserStatusType.Revoked, revokedUser.Status);
}

Expand All @@ -429,7 +428,7 @@ public async Task Put_NotFound()
Schemas = new List<string> { ScimConstants.Scim2SchemaError }
};

var context = await _factory.UsersPutAsync(ScimApplicationFactory.TestOrganizationId1, organizationUserId.ToString(), inputModel);
var context = await _factory.UsersPutAsync(ScimApplicationFactory.TestOrganizationId1, organizationUserId, inputModel);

Assert.Equal(StatusCodes.Status404NotFound, context.Response.StatusCode);

Expand All @@ -456,7 +455,7 @@ public async Task Patch_ReplaceRevoke_Success()

var databaseContext = _factory.GetDatabaseContext();

var organizationUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id.ToString() == organizationUserId);
var organizationUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id == organizationUserId);
Assert.Equal(OrganizationUserStatusType.Revoked, organizationUser.Status);
}

Expand All @@ -479,14 +478,14 @@ public async Task Patch_ReplaceRestore_Success()

var databaseContext = _factory.GetDatabaseContext();

var organizationUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id.ToString() == organizationUserId);
var organizationUser = databaseContext.OrganizationUsers.FirstOrDefault(g => g.Id == organizationUserId);
Assert.NotEqual(OrganizationUserStatusType.Revoked, organizationUser.Status);
}

[Fact]
public async Task Patch_NotFound()
{
var organizationUserId = Guid.NewGuid().ToString();
var organizationUserId = Guid.NewGuid();
var inputModel = new Models.ScimPatchModel
{
Operations = new List<ScimPatchModel.OperationModel>(),
Expand Down Expand Up @@ -519,13 +518,13 @@ public async Task Delete_Success()

var databaseContext = _factory.GetDatabaseContext();
Assert.Equal(_initialUserCount - 1, databaseContext.OrganizationUsers.Count());
Assert.False(databaseContext.OrganizationUsers.Any(g => g.Id.ToString() == organizationUserId));
Assert.False(databaseContext.OrganizationUsers.Any(g => g.Id == organizationUserId));
}

[Fact]
public async Task Delete_NotFound()
{
var organizationUserId = Guid.NewGuid().ToString();
var organizationUserId = Guid.NewGuid();
var inputModel = new ScimUserRequestModel();
var expectedResponse = new ScimErrorResponseModel
{
Expand Down
Loading

0 comments on commit a79a523

Please sign in to comment.