44using System . Threading . Tasks ;
55using Certify . Core . Management . Access ;
66using Certify . Datastore . SQLite ;
7+ using Certify . Models ;
78using Certify . Models . Hub ;
9+ using Certify . Models . Providers ;
810using Certify . Providers ;
11+ using Microsoft . Extensions . Logging ;
912using Microsoft . VisualStudio . TestTools . UnitTesting ;
1013
1114namespace Certify . Core . Tests . DataStores
@@ -15,6 +18,7 @@ public class AccessControlDataStoreTests
1518 {
1619 private string _storeType = "sqlite" ;
1720 private const string TEST_PATH = "Tests" ;
21+ private ILog _log = new Loggy ( LoggerFactory . Create ( builder => builder . AddDebug ( ) ) . CreateLogger < AccessControlDataStoreTests > ( ) ) ;
1822
1923 public static IEnumerable < object [ ] > TestDataStores
2024 {
@@ -42,14 +46,14 @@ private IConfigurationStore GetStore(string storeType = null)
4246 {
4347 store = new SQLiteConfigurationStore ( storageSubfolder : TEST_PATH ) ;
4448 }
45- /* else if (storeType == "postgres")
46- {
47- return new PostgresCredentialStore(Environment.GetEnvironmentVariable("CERTIFY_TEST_POSTGRES"));
48- }
49- else if (storeType == "sqlserver")
50- {
51- return new SQLServerCredentialStore(Environment.GetEnvironmentVariable("CERTIFY_TEST_SQLSERVER"));
52- }*/
49+ /* else if (storeType == "postgres")
50+ {
51+ return new PostgresCredentialStore(Environment.GetEnvironmentVariable("CERTIFY_TEST_POSTGRES"));
52+ }
53+ else if (storeType == "sqlserver")
54+ {
55+ return new SQLServerCredentialStore(Environment.GetEnvironmentVariable("CERTIFY_TEST_SQLSERVER"));
56+ }*/
5357 else
5458 {
5559 throw new ArgumentOutOfRangeException ( nameof ( storeType ) , "Unsupported store type " + storeType ) ;
@@ -117,7 +121,8 @@ public async Task TestStoreRole(string storeType)
117121 public void TestStorePasswordHashing ( )
118122 {
119123 var store = GetStore ( _storeType ) ;
120- var access = new AccessControl ( null , store ) ;
124+
125+ var access = new AccessControl ( _log , store ) ;
121126
122127 var firstHash = access . HashPassword ( "secret" ) ;
123128
@@ -133,7 +138,7 @@ public async Task TestStoreGeneralAccessControl(string storeType)
133138
134139 var store = GetStore ( storeType ?? _storeType ) ;
135140
136- var access = new AccessControl ( null , store ) ;
141+ var access = new AccessControl ( _log , store ) ;
137142
138143 var adminSp = new SecurityPrincipal
139144 {
@@ -164,10 +169,10 @@ public async Task TestStoreGeneralAccessControl(string storeType)
164169
165170 await access . AddSecurityPrincipal ( adminSp . Id , adminSp , bypassIntegrityCheck : true ) ;
166171
167- await access . AddAssignedRole ( adminSp . Id , new AssignedRole { Id = new Guid ( ) . ToString ( ) , SecurityPrincipalId = adminSp . Id , RoleId = StandardRoles . Administrator . Id } ) ;
172+ await access . AddAssignedRole ( adminSp . Id , new AssignedRole { Id = new Guid ( ) . ToString ( ) , SecurityPrincipalId = adminSp . Id , RoleId = StandardRoles . Administrator . Id } , bypassIntegrityCheck : true ) ;
168173
169- // add second security principal, bypass role check as this is just a data store test
170- var added = await access . AddSecurityPrincipal ( adminSp . Id , consumerSp , bypassIntegrityCheck : true ) ;
174+ // add second security principal, allow role check as admin user should now exist with required role
175+ var added = await access . AddSecurityPrincipal ( adminSp . Id , consumerSp ) ;
171176
172177 Assert . IsTrue ( added , "Should be able to add a security principal" ) ;
173178
0 commit comments