@@ -17,80 +17,91 @@ class StorageEngineSyncRequirementsTests: XCTestCase {
17
17
18
18
func testRequiresAuthPluginFalseForMissingAuthRules( ) {
19
19
let apiPlugin = MockAPICategoryPlugin ( )
20
- let result = StorageEngine . requiresAuthPlugin ( apiPlugin)
21
- XCTAssertFalse ( result )
20
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authModeStrategy : . default ) )
21
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin , authModeStrategy : . multiAuth ) )
22
22
}
23
23
24
24
func testRequiresAuthPluginSingleAuthRuleAPIKey( ) {
25
25
let apiPlugin = MockAPICategoryPlugin ( )
26
26
let authRules = [ AuthRule ( allow: . owner, provider: . apiKey) ]
27
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
27
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
28
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
28
29
}
29
30
30
31
func testRequiresAuthPluginSingleAuthRuleOIDC( ) {
31
32
let apiPlugin = MockAPICategoryPlugin ( )
32
33
let authRules = [ AuthRule ( allow: . owner, provider: . oidc) ]
33
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
34
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
35
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
34
36
}
35
37
36
38
func testRequiresAuthPluginSingleAuthRuleFunction( ) {
37
39
let apiPlugin = MockAPICategoryPlugin ( )
38
40
let authRules = [ AuthRule ( allow: . private, provider: . function) ]
39
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
41
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
42
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
40
43
}
41
44
42
45
func testRequiresAuthPluginSingleAuthRuleUserPools( ) {
43
46
let apiPlugin = MockAPICategoryPlugin ( )
44
47
let authRules = [ AuthRule ( allow: . owner, provider: . userPools) ]
45
- XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
48
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
49
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
46
50
}
47
51
48
52
func testRequiresAuthPluginSingleAuthRuleIAM( ) {
49
53
let apiPlugin = MockAPICategoryPlugin ( )
50
54
let authRules = [ AuthRule ( allow: . owner, provider: . iam) ]
51
- XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
55
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
56
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
52
57
}
53
58
54
59
func testRequiresAuthPluginNoProvidersWithAuthTypeFunction( ) {
55
60
let authRules = [ AuthRule ( allow: . owner) ]
56
61
let apiPlugin = MockAPIAuthInformationPlugin ( )
57
62
apiPlugin. authType = . function
58
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
63
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
64
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
59
65
}
60
66
61
67
func testRequiresAuthPluginNoProvidersWithAuthTypeAPIKey( ) {
62
68
let authRules = [ AuthRule ( allow: . owner) ]
63
69
let apiPlugin = MockAPIAuthInformationPlugin ( )
64
70
apiPlugin. authType = . apiKey
65
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
71
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
72
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
66
73
}
67
74
68
75
func testRequiresAuthPluginNoProvidersWithAuthTypeUserPools( ) {
69
76
let authRules = [ AuthRule ( allow: . owner) ]
70
77
let apiPlugin = MockAPIAuthInformationPlugin ( )
71
78
apiPlugin. authType = . amazonCognitoUserPools
72
- XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
79
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
80
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
73
81
}
74
82
75
83
func testRequiresAuthPluginNoProvidersWithAuthTypeIAM( ) {
76
84
let authRules = [ AuthRule ( allow: . owner) ]
77
85
let apiPlugin = MockAPIAuthInformationPlugin ( )
78
86
apiPlugin. authType = . awsIAM
79
- XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
87
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
88
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
80
89
}
81
90
82
91
func testRequiresAuthPluginNoProvidersWithAuthTypeODIC( ) {
83
92
let authRules = [ AuthRule ( allow: . owner) ]
84
93
let apiPlugin = MockAPIAuthInformationPlugin ( )
85
94
apiPlugin. authType = . openIDConnect
86
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
95
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
96
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
87
97
}
88
98
89
99
func testRequiresAuthPluginNoProvidersWithAuthTypeNone( ) {
90
100
let authRules = [ AuthRule ( allow: . owner) ]
91
101
let apiPlugin = MockAPIAuthInformationPlugin ( )
92
102
apiPlugin. authType = AWSAuthorizationType . none
93
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
103
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
104
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
94
105
}
95
106
96
107
func testRequiresAuthPluginOIDCProvider( ) {
@@ -99,7 +110,41 @@ class StorageEngineSyncRequirementsTests: XCTestCase {
99
110
apiPlugin. defaultAuthTypeError = APIError . unknown ( " Could not get default auth type " , " " , nil )
100
111
let oidcProvider = MockOIDCAuthProvider ( )
101
112
apiPlugin. authProviderFactory = MockAPIAuthProviderFactory ( oidcProvider: oidcProvider)
102
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
113
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
114
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
115
+ }
116
+
117
+ func testRequiresAuthPluginOIDCProvider_MultiAuthRules( ) {
118
+ // OIDC requires an auth provider on the API, this is added below
119
+ let authRules = [ AuthRule ( allow: . owner, provider: . oidc) ,
120
+ AuthRule ( allow: . private, provider: . iam) ]
121
+ let apiPlugin = MockAPIAuthInformationPlugin ( )
122
+ apiPlugin. defaultAuthTypeError = APIError . unknown ( " Could not get default auth type " , " " , nil )
123
+ let oidcProvider = MockOIDCAuthProvider ( )
124
+ apiPlugin. authProviderFactory = MockAPIAuthProviderFactory ( oidcProvider: oidcProvider)
125
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin,
126
+ authRules: authRules,
127
+ authModeStrategy: . default) ,
128
+ " Should be false since OIDC is the default auth type on the API. " )
129
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin,
130
+ authRules: authRules,
131
+ authModeStrategy: . multiAuth) ,
132
+ " Should be true since IAM requires auth plugin. " )
133
+ }
134
+
135
+ func testRequiresAuthPluginUserPoolProvider_MultiAuthRules( ) {
136
+ let authRules = [ AuthRule ( allow: . owner, provider: . userPools) ,
137
+ AuthRule ( allow: . private, provider: . iam) ]
138
+ let apiPlugin = MockAPIAuthInformationPlugin ( )
139
+ apiPlugin. authType = AWSAuthorizationType . amazonCognitoUserPools
140
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin,
141
+ authRules: authRules,
142
+ authModeStrategy: . default) ,
143
+ " Should be true since UserPool is the default auth type on the API. " )
144
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin,
145
+ authRules: authRules,
146
+ authModeStrategy: . multiAuth) ,
147
+ " Should be true since both UserPool and IAM requires auth plugin. " )
103
148
}
104
149
105
150
func testRequiresAuthPluginFunctionProvider( ) {
@@ -108,14 +153,16 @@ class StorageEngineSyncRequirementsTests: XCTestCase {
108
153
apiPlugin. defaultAuthTypeError = APIError . unknown ( " Could not get default auth type " , " " , nil )
109
154
let functionProvider = MockFunctionAuthProvider ( )
110
155
apiPlugin. authProviderFactory = MockAPIAuthProviderFactory ( functionProvider: functionProvider)
111
- XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
156
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
157
+ XCTAssertFalse ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
112
158
}
113
159
114
160
func testRequiresAuthPluginWithAuthRules( ) {
115
161
let authRules = [ AuthRule ( allow: . owner) ]
116
162
let apiPlugin = MockAPIAuthInformationPlugin ( )
117
163
apiPlugin. defaultAuthTypeError = APIError . unknown ( " Could not get default auth type " , " " , nil )
118
- XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules) )
164
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . default) )
165
+ XCTAssertTrue ( StorageEngine . requiresAuthPlugin ( apiPlugin, authRules: authRules, authModeStrategy: . multiAuth) )
119
166
}
120
167
121
168
// MARK: - AuthRules tests
0 commit comments