Skip to content

Commit

Permalink
Add more tenant blob store tests (#364)
Browse files Browse the repository at this point in the history
* Add more tenant blob store tests
* Removed preview ref from pipeline
* Fix test problems around well-known container recreation
  • Loading branch information
idg10 authored Dec 17, 2021
1 parent 430f8fa commit 1c30264
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Marain.Tenancy.Storage.Azure.BlobStorage.Specs.Bindings
{
using System;
using System.Collections.Generic;

using Corvus.Tenancy;
Expand All @@ -17,6 +18,8 @@ public TenantProperties(ScenarioDiContainer diContainer)

public Dictionary<string, ITenant> Tenants { get; } = new Dictionary<string, ITenant>();

public Dictionary<string, Guid> WellKnownGuids { get; } = new ();

public HashSet<string> TenantsToDelete { get; } = new HashSet<string>();

public HashSet<string> WellKnownTenantsToDelete { get; } = new HashSet<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Marain.Tenancy.Storage.Azure.BlobStorage.Specs.Bindings
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Threading.Tasks;

using Corvus.Extensions.Json;
Expand Down Expand Up @@ -72,10 +74,20 @@ public async Task GivenTheRootTenantHasAChildTenantWithPropertiesCalled(
this.AddTenantToDelete(newTenant.Id);
}

[Given("the root tenant has a well-known child tenant called '([^']*)' with a Guid of '([^']*)' labelled '([^']*)'")]
[Given("a well-known tenant Guid labelled '([^']*)'")]
public void GivenAWell_KnownTenantGuidLabelled(string label)
{
// We need "well-known" ids to be different each time we run the test, because
// otherwise, we fall foul of Azure Storage's inability to create a container
// with the same name as a container you recently deleted.
this.WellKnownGuids.Add(label, Guid.NewGuid());
}

[Given(@"the root tenant has a well-known \(from the Guid labelled '([^']*)'\) child tenant called '([^']*)' labelled '([^']*)'")]
public async Task GivenTheRootTenantHasAWellKnownChildTenantCalled(
string tenantName, Guid wellKnownId, string tenantLabel)
string wellKnownGuidLabel, string tenantName, string tenantLabel)
{
Guid wellKnownId = this.WellKnownGuids[wellKnownGuidLabel];
ITenant newTenant = await this.containerSetup.EnsureWellKnownChildTenantExistsAsync(
RootTenant.RootTenantId, wellKnownId, tenantName, this.PropagateRootTenancyStorageConfigAsV2);
this.Tenants.Add(tenantLabel, newTenant);
Expand All @@ -94,10 +106,11 @@ public async Task GivenTheRootTenantHasAChildTenantCalled(
this.AddTenantToDelete(newTenant.Id);
}

[Given("the tenant labelled '([^']*)' has a well-known child tenant called '([^']*)' with a Guid of '([^']*)' labelled '([^']*)'")]
[Given(@"the tenant labelled '([^']*)' has a well-known \(from the Guid labelled '([^']*)'\) child tenant called '([^']*)' labelled '([^']*)'")]
public async Task GivenTheRootTenantHasAChildTenantCalled(
string parentTenantLabel, string tenantName, Guid wellKnownId, string newTenantLabel)
string parentTenantLabel, string wellKnownGuidLabel, string tenantName, string newTenantLabel)
{
Guid wellKnownId = this.WellKnownGuids[wellKnownGuidLabel];
ITenant parent = this.Tenants[parentTenantLabel];
ITenant newTenant = await this.containerSetup.EnsureWellKnownChildTenantExistsAsync(
parent.Id, wellKnownId, tenantName, this.PropagateRootTenancyStorageConfigAsV2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public TenantStepsBase(TenantProperties tenantProperties)

public HashSet<string> TenantsToDelete => this.tenantProperties.TenantsToDelete;

public Dictionary<string, Guid> WellKnownGuids => this.tenantProperties.WellKnownGuids;

public HashSet<string> WellKnownTenantsToDelete => this.tenantProperties.WellKnownTenantsToDelete;

public ITenantStore TenantStore => this.DiContainer.TenantStore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Scenario: Create a child of the root tenant
And the tenant labelled 'ChildTenant' should have storage configuration equivalent to the root

Scenario: Create a child of the root tenant with a well known Id
When I create a well known child tenant of the root tenant called 'ChildTenant1' with a Guid of 'F446F305-993B-49A4-B5FA-010EE2AF0FA2' labelled 'ChildTenant'
Given a well-known tenant Guid labelled 'WellKnown1'
When I create a well known (from the Guid labelled 'WellKnown1') child tenant of the root tenant called 'ChildTenant1' labelled 'ChildTenant'
And I get the tenant with the id from label 'ChildTenant' labelled 'Result'
Then the tenant details labelled 'ChildTenant' should match the tenant details labelled 'Result'
And the tenant details labelled 'ChildTenant' should have tenant Id '05f346f43b99a449b5fa010ee2af0fa2'
And the tenant details labelled 'ChildTenant' should have tenant Id that is the hash of the Guid labelled 'WellKnown1'
And the tenant labelled 'ChildTenant' should have storage configuration equivalent to the root

Scenario: Create a child of a child of the root tenant
Expand All @@ -28,28 +29,36 @@ Scenario: Create a child of a child of the root tenant
And the tenant labelled 'Tenant2' should have storage configuration equivalent to the root

Scenario: Create a child of a child with well known Ids
Given the root tenant has a well-known child tenant called 'ChildTenant1' with a Guid of 'EE17B20B-B372-4493-8145-9DD95516B9AF' labelled 'Tenant1'
When I create a well known child of the tenant labelled 'Tenant1' named 'ChildTenant2' with a Guid of 'DD045C05-E7FB-4214-8878-F9E7CA9B0F5F' labelled 'Tenant2'
Given a well-known tenant Guid labelled 'WellKnown1'
And a well-known tenant Guid labelled 'WellKnown2'
And the root tenant has a well-known (from the Guid labelled 'WellKnown1') child tenant called 'ChildTenant1' labelled 'Tenant1'
When I create a well known (from the Guid labelled 'WellKnown2') child of the tenant labelled 'Tenant1' named 'ChildTenant2' labelled 'Tenant2'
And I get the tenant with the id from label 'Tenant2' labelled 'Result'
Then the tenant details labelled 'Tenant2' should match the tenant details labelled 'Result'
And the tenant details labelled 'Tenant1' should have tenant Id '0bb217ee72b3934481459dd95516b9af'
And the tenant details labelled 'Tenant2' should have tenant Id '0bb217ee72b3934481459dd95516b9af055c04ddfbe714428878f9e7ca9b0f5f'
And the tenant details labelled 'Tenant1' should have tenant Id that is the hash of the Guid labelled 'WellKnown1'
And the tenant details labelled 'Tenant2' should have tenant Id that is the concatenated hashes of the Guids labelled 'WellKnown1' and 'WellKnown2'
And the tenant labelled 'Tenant2' should have storage configuration equivalent to the root

Scenario: Creating a child of a child with a well known Id that is already in use by a child of the same parent throws an ArgumentException
Given the root tenant has a well-known child tenant called 'ChildTenant1' with a Guid of 'ABE7C6C9-8494-4797-B52E-5C7B3EF1CE56' labelled 'Tenant1'
And the tenant labelled 'Tenant1' has a well-known child tenant called 'ChildTenant2' with a Guid of 'DD045C05-E7FB-4214-8878-F9E7CA9B0F5F' labelled 'Tenant2'
When I try to create a well known child of the tenant labelled 'Tenant1' named 'ChildTenant3' with a Guid of 'DD045C05-E7FB-4214-8878-F9E7CA9B0F5F'
Given a well-known tenant Guid labelled 'WellKnown1'
And a well-known tenant Guid labelled 'WellKnown2'
And the root tenant has a well-known (from the Guid labelled 'WellKnown1') child tenant called 'ChildTenant1' labelled 'Tenant1'
And the tenant labelled 'Tenant1' has a well-known (from the Guid labelled 'WellKnown2') child tenant called 'ChildTenant2' labelled 'Tenant2'
When I try to create a well known child (from the Guid labelled 'WellKnown2') of the tenant labelled 'Tenant1' named 'ChildTenant3'
Then CreateWellKnownChildTenantAsync thould throw an ArgumentException

Scenario: Creating children that have the same well known Ids under different parents succeeds
Given the root tenant has a well-known child tenant called 'ChildTenant1' with a Guid of '2A182D6E-FF13-4A73-87AF-0B58D8243603' labelled 'Parent1'
And the root tenant has a well-known child tenant called 'ChildTenant2' with a Guid of '086D75A1-DA07-4C90-BEA7-857A6C126280' labelled 'Parent2'
And the tenant labelled 'Parent1' has a well-known child tenant called 'ChildTenant3' with a Guid of '2A182D6E-FF13-4A73-87AF-0B58D8243603' labelled 'ChildOfParent1'
When I create a well known child of the tenant labelled 'Parent2' named 'ChildTenant4' with a Guid of '2A182D6E-FF13-4A73-87AF-0B58D8243603' labelled 'ChildOfParent2'
Given a well-known tenant Guid labelled 'WellKnown1'
And a well-known tenant Guid labelled 'WellKnown2'
And a well-known tenant Guid labelled 'WellKnown3'
And a well-known tenant Guid labelled 'WellKnown4'
And the root tenant has a well-known (from the Guid labelled 'WellKnown1') child tenant called 'ChildTenant1' labelled 'Parent1'
And the root tenant has a well-known (from the Guid labelled 'WellKnown2') child tenant called 'ChildTenant2' labelled 'Parent2'
And the tenant labelled 'Parent1' has a well-known (from the Guid labelled 'WellKnown3') child tenant called 'ChildTenant3' labelled 'ChildOfParent1'
When I create a well known (from the Guid labelled 'WellKnown4') child of the tenant labelled 'Parent2' named 'ChildTenant4' labelled 'ChildOfParent2'
And I get the tenant with the id from label 'ChildOfParent1' labelled 'Result1'
And I get the tenant with the id from label 'ChildOfParent2' labelled 'Result2'
Then the tenant details labelled 'Result1' should have tenant Id '6e2d182a13ff734a87af0b58d82436036e2d182a13ff734a87af0b58d8243603'
And the tenant details labelled 'Result2' should have tenant Id 'a1756d0807da904cbea7857a6c1262806e2d182a13ff734a87af0b58d8243603'
Then the tenant details labelled 'Result1' should have tenant Id that is the concatenated hashes of the Guids labelled 'WellKnown1' and 'WellKnown3'
And the tenant details labelled 'Result2' should have tenant Id that is the concatenated hashes of the Guids labelled 'WellKnown2' and 'WellKnown4'
And the tenant labelled 'Result1' should have storage configuration equivalent to the root
And the tenant labelled 'Result2' should have storage configuration equivalent to the root
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,43 @@ Scenario: Delete a child
| ChildTenant4 |
| ChildTenant5 |

# TODO:
# Attempt to delete non-existent tenant
# Attempt to delete child for which parent is non-existent
# Attempt to delete a non-empty parent
# Delete child of a child?
# What happens if we try to delete the root?
Scenario: Delete a child of a child
Given the root tenant has a child tenant called 'ChildTenant1' labelled 'ParentTenant'
And the tenant labelled 'ParentTenant' has a child tenant called 'ChildTenant2' labelled 'ChildTenant2'
And the tenant labelled 'ParentTenant' has a child tenant called 'ChildTenant3' labelled 'ChildTenant3'
And the tenant labelled 'ParentTenant' has a child tenant called 'ChildTenant4' labelled 'ChildTenant4'
And the tenant labelled 'ParentTenant' has a child tenant called 'ChildTenant5' labelled 'ChildTenant5'
And the tenant labelled 'ChildTenant2' has a child tenant called 'ChildTenant6' labelled 'ChildTenant6'
And the tenant labelled 'ChildTenant3' has a child tenant called 'ChildTenant7' labelled 'ChildTenant7'
And the tenant labelled 'ChildTenant3' has a child tenant called 'ChildTenant8' labelled 'ChildTenant8'
And the tenant labelled 'ChildTenant3' has a child tenant called 'ChildTenant9' labelled 'ChildTenant9'
When I delete the tenant with the id from label 'ChildTenant8'
And I get the children of the tenant with the label 'ChildTenant3' with maxItems 20
Then the ids of all the children across all pages should match these tenant ids
| TenantName |
| ChildTenant7 |
| ChildTenant9 |

Scenario: Delete a non-existent child of root
When I attempt to delete a tenant with the id that looks like a child of the root tenant but which does not exist
Then the attempt to delete a tenant should throw a TenantNotFoundException

Scenario: Delete a non-existent child of non-existent child of root
When I attempt to delete a tenant with the id that looks like a child of a child of the root tenant, where neither exists
Then the attempt to delete a tenant should throw a TenantNotFoundException

Scenario: Delete a non-existent child of existing parent
Given the root tenant has a child tenant called 'ChildTenant1' labelled 'ParentTenant'
When I attempt to delete a tenant with the id that looks like a child of 'ParentTenant' but which does not exist
Then the attempt to delete a tenant should throw a TenantNotFoundException

Scenario: Delete root tenant
When I attempt to delete the root tenant
Then the attempt to delete a tenant should throw an ArgumentException

Scenario: Delete a non-empty parent
Given the root tenant has a child tenant called 'ChildTenant1' labelled 'ParentTenant'
And the tenant labelled 'ParentTenant' has a child tenant called 'ChildTenant2' labelled 'ChildTenant2'
And the tenant labelled 'ParentTenant' has a child tenant called 'ChildTenant3' labelled 'ChildTenant3'
When I attempt to delete the tenant with the id from label 'ParentTenant'
Then the attempt to delete a tenant should throw an ArgumentException
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,29 @@ Scenario: Rename a child tenant
And the tenant labelled 'UpdateResult' should have the name 'NewName'
And the tenant labelled 'GetResult' should have the name 'NewName'

# TODO:
# Try to rename a non-existent tenant
# Try to rename a child for which parent is non-existent
# Rename child of child?
# What if we try to rename the root?
Scenario: Rename a child of a child
Given the root tenant has a child tenant called 'ChildTenant1' labelled 'ParentTenant'
And the tenant labelled 'ParentTenant' has a child tenant called 'ChildTenant2' labelled 'ChildTenant2'
When I change the name of the tenant labelled 'ChildTenant2' to 'NewName' and label the returned tenant 'UpdateResult'
And I get the tenant with the id from label 'ChildTenant2' labelled 'GetResult'
Then the tenant labelled 'UpdateResult' should have the same ID as the tenant labelled 'ChildTenant2'
And the tenant labelled 'GetResult' should have the same ID as the tenant labelled 'ChildTenant2'
And the tenant labelled 'UpdateResult' should have the name 'NewName'
And the tenant labelled 'GetResult' should have the name 'NewName'

Scenario: Rename a non-existent child of root tenant
When I attempt to change the name of a tenant with the id that looks like a child of the root tenant but which does not exist
Then the attempt to change the name of a tenant should throw a TenantNotFoundException

Scenario: Rename a non-existent child of non-existent child of root
When I attempt to change the name of a tenant with the id that looks like a child of a child of the root tenant, where neither exists
Then the attempt to change the name of a tenant should throw a TenantNotFoundException

Scenario: Rename a non-existent child of existing parent
Given the root tenant has a child tenant called 'ChildTenant1' labelled 'ParentTenant'
When I attempt to change the name of a tenant with the id that looks like a child of 'ParentTenant' but which does not exist
Then the attempt to change the name of a tenant should throw a TenantNotFoundException

Scenario: Rename root tenant
When I attempt to change the name of the root tenant
Then the attempt to change the name of a tenant should throw an ArgumentException
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public async Task GivenICreateAChildOfTheRootTenantCalledWithTheDetailsAvailable
this.AddTenantToDelete(newTenant.Id);
}

[When(@"I create a well known child tenant of the root tenant called '([^']*)' with a Guid of '([^']*)' labelled '([^']*)'")]
[When(@"I create a well known \(from the Guid labelled '([^']*)'\) child tenant of the root tenant called '([^']*)' labelled '([^']*)'")]
public async Task GivenICreateAWellKnownChildOfTheRootTenantCalledWithTheDetailsAvailableAsAsync(
string tenantName, Guid wellKnownGuid, string newTenantLabel)
string wellKnownGuidLabel, string tenantName, string newTenantLabel)
{
Guid wellKnownGuid = this.WellKnownGuids[wellKnownGuidLabel];

// This is called in scenarios where we want the tenant creation to go through the
// tenant store under test even when the setup mode is direct-to-store, because we're
// validating that the information returned from the store works when we use it again
Expand All @@ -70,26 +72,28 @@ public async Task GivenICreateAChildOfAChildOfTheRootTenantAsync(
this.AddTenantToDelete(newTenant.Id);
}

[When(@"I create a well known child of the tenant labelled '([^']*)' named '([^']*)' with a Guid of '([^']*)' labelled '([^']*)'")]
[When(@"I create a well known \(from the Guid labelled '([^']*)'\) child of the tenant labelled '([^']*)' named '([^']*)' labelled '([^']*)'")]
public async Task GivenICreateAWellKnownChildOfAChildOfATenantAsync(
string parentTenantLabel, string newTenantName, Guid wellKnownId, string newTenantLabel)
string wellKnownGuidLabel, string parentTenantLabel, string newTenantName, string newTenantLabel)
{
Guid wellKnownGuid = this.WellKnownGuids[wellKnownGuidLabel];
ITenant parent = this.Tenants[parentTenantLabel];
ITenant newTenant = await this.TenantStore.CreateWellKnownChildTenantAsync(
parent.Id, wellKnownId, newTenantName);
parent.Id, wellKnownGuid, newTenantName);
this.Tenants.Add(newTenantLabel, newTenant);
this.AddWellKnownTenantToDelete(newTenant.Id);
}

[When(@"I try to create a well known child of the tenant labelled '([^']*)' named '([^']*)' with a Guid of '([^']*)'")]
[When(@"I try to create a well known child \(from the Guid labelled '([^']*)'\) of the tenant labelled '([^']*)' named '([^']*)'")]
public async Task GivenITryToCreateAWellKnownChildOfAChildOfATenantAsync(
string parentTenantLabel, string newTenantName, Guid wellKnownId)
string wellKnownGuidLabel, string parentTenantLabel, string newTenantName)
{
Guid wellKnownGuid = this.WellKnownGuids[wellKnownGuidLabel];
ITenant parent = this.Tenants[parentTenantLabel];
try
{
ITenant newTenant = await this.TenantStore.CreateWellKnownChildTenantAsync(
parent.Id, wellKnownId, newTenantName);
parent.Id, wellKnownGuid, newTenantName);
}
catch (Exception x)
{
Expand Down
Loading

0 comments on commit 1c30264

Please sign in to comment.