4
4
using System . Threading . Tasks ;
5
5
using Certify . Core . Management . Access ;
6
6
using Certify . Datastore . SQLite ;
7
+ using Certify . Models ;
7
8
using Certify . Models . Hub ;
9
+ using Certify . Models . Providers ;
8
10
using Certify . Providers ;
11
+ using Microsoft . Extensions . Logging ;
9
12
using Microsoft . VisualStudio . TestTools . UnitTesting ;
10
13
11
14
namespace Certify . Core . Tests . DataStores
@@ -15,6 +18,7 @@ public class AccessControlDataStoreTests
15
18
{
16
19
private string _storeType = "sqlite" ;
17
20
private const string TEST_PATH = "Tests" ;
21
+ private ILog _log = new Loggy ( LoggerFactory . Create ( builder => builder . AddDebug ( ) ) . CreateLogger < AccessControlDataStoreTests > ( ) ) ;
18
22
19
23
public static IEnumerable < object [ ] > TestDataStores
20
24
{
@@ -42,14 +46,14 @@ private IConfigurationStore GetStore(string storeType = null)
42
46
{
43
47
store = new SQLiteConfigurationStore ( storageSubfolder : TEST_PATH ) ;
44
48
}
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
+ }*/
53
57
else
54
58
{
55
59
throw new ArgumentOutOfRangeException ( nameof ( storeType ) , "Unsupported store type " + storeType ) ;
@@ -117,7 +121,8 @@ public async Task TestStoreRole(string storeType)
117
121
public void TestStorePasswordHashing ( )
118
122
{
119
123
var store = GetStore ( _storeType ) ;
120
- var access = new AccessControl ( null , store ) ;
124
+
125
+ var access = new AccessControl ( _log , store ) ;
121
126
122
127
var firstHash = access . HashPassword ( "secret" ) ;
123
128
@@ -133,7 +138,7 @@ public async Task TestStoreGeneralAccessControl(string storeType)
133
138
134
139
var store = GetStore ( storeType ?? _storeType ) ;
135
140
136
- var access = new AccessControl ( null , store ) ;
141
+ var access = new AccessControl ( _log , store ) ;
137
142
138
143
var adminSp = new SecurityPrincipal
139
144
{
@@ -164,10 +169,10 @@ public async Task TestStoreGeneralAccessControl(string storeType)
164
169
165
170
await access . AddSecurityPrincipal ( adminSp . Id , adminSp , bypassIntegrityCheck : true ) ;
166
171
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 ) ;
168
173
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 ) ;
171
176
172
177
Assert . IsTrue ( added , "Should be able to add a security principal" ) ;
173
178
0 commit comments