@@ -14,6 +14,7 @@ import (
14
14
"github.com/coder/coder/v2/coderd/database"
15
15
"github.com/coder/coder/v2/coderd/database/db2sdk"
16
16
"github.com/coder/coder/v2/coderd/database/dbauthz"
17
+ "github.com/coder/coder/v2/coderd/database/dbfake"
17
18
"github.com/coder/coder/v2/coderd/database/dbgen"
18
19
"github.com/coder/coder/v2/coderd/database/dbtestutil"
19
20
"github.com/coder/coder/v2/coderd/entitlements"
@@ -89,7 +90,8 @@ func TestOrganizationSync(t *testing.T) {
89
90
Name : "SingleOrgDeployment" ,
90
91
Case : func (t * testing.T , db database.Store ) OrganizationSyncTestCase {
91
92
def , _ := db .GetDefaultOrganization (context .Background ())
92
- other := dbgen .Organization (t , db , database.Organization {})
93
+ other := dbfake .Organization (t , db ).Do ()
94
+ deleted := dbfake .Organization (t , db ).Deleted (true ).Do ()
93
95
return OrganizationSyncTestCase {
94
96
Entitlements : entitled ,
95
97
Settings : idpsync.DeploymentSyncSettings {
@@ -123,11 +125,19 @@ func TestOrganizationSync(t *testing.T) {
123
125
})
124
126
dbgen .OrganizationMember (t , db , database.OrganizationMember {
125
127
UserID : user .ID ,
126
- OrganizationID : other .ID ,
128
+ OrganizationID : other .Org .ID ,
129
+ })
130
+ dbgen .OrganizationMember (t , db , database.OrganizationMember {
131
+ UserID : user .ID ,
132
+ OrganizationID : deleted .Org .ID ,
127
133
})
128
134
},
129
135
Sync : ExpectedUser {
130
- Organizations : []uuid.UUID {def .ID , other .ID },
136
+ Organizations : []uuid.UUID {
137
+ def .ID , other .Org .ID ,
138
+ // The user remains in the deleted org because no idp sync happens.
139
+ deleted .Org .ID ,
140
+ },
131
141
},
132
142
},
133
143
},
@@ -138,17 +148,19 @@ func TestOrganizationSync(t *testing.T) {
138
148
Name : "MultiOrgWithDefault" ,
139
149
Case : func (t * testing.T , db database.Store ) OrganizationSyncTestCase {
140
150
def , _ := db .GetDefaultOrganization (context .Background ())
141
- one := dbgen .Organization (t , db , database.Organization {})
142
- two := dbgen .Organization (t , db , database.Organization {})
143
- three := dbgen .Organization (t , db , database.Organization {})
151
+ one := dbfake .Organization (t , db ).Do ()
152
+ two := dbfake .Organization (t , db ).Do ()
153
+ three := dbfake .Organization (t , db ).Do ()
154
+ deleted := dbfake .Organization (t , db ).Deleted (true ).Do ()
144
155
return OrganizationSyncTestCase {
145
156
Entitlements : entitled ,
146
157
Settings : idpsync.DeploymentSyncSettings {
147
158
OrganizationField : "organizations" ,
148
159
OrganizationMapping : map [string ][]uuid.UUID {
149
- "first" : {one .ID },
150
- "second" : {two .ID },
151
- "third" : {three .ID },
160
+ "first" : {one .Org .ID },
161
+ "second" : {two .Org .ID },
162
+ "third" : {three .Org .ID },
163
+ "deleted" : {deleted .Org .ID },
152
164
},
153
165
OrganizationAssignDefault : true ,
154
166
},
@@ -167,7 +179,7 @@ func TestOrganizationSync(t *testing.T) {
167
179
{
168
180
Name : "AlreadyInOrgs" ,
169
181
Claims : jwt.MapClaims {
170
- "organizations" : []string {"second" , "extra" },
182
+ "organizations" : []string {"second" , "extra" , "deleted" },
171
183
},
172
184
ExpectedParams : idpsync.OrganizationParams {
173
185
SyncEntitled : true ,
@@ -180,18 +192,18 @@ func TestOrganizationSync(t *testing.T) {
180
192
})
181
193
dbgen .OrganizationMember (t , db , database.OrganizationMember {
182
194
UserID : user .ID ,
183
- OrganizationID : one .ID ,
195
+ OrganizationID : one .Org . ID ,
184
196
})
185
197
},
186
198
Sync : ExpectedUser {
187
- Organizations : []uuid.UUID {def .ID , two .ID },
199
+ Organizations : []uuid.UUID {def .ID , two .Org . ID },
188
200
},
189
201
},
190
202
{
191
203
Name : "ManyClaims" ,
192
204
Claims : jwt.MapClaims {
193
205
// Add some repeats
194
- "organizations" : []string {"second" , "extra" , "first" , "third" , "second" , "second" },
206
+ "organizations" : []string {"second" , "extra" , "first" , "third" , "second" , "second" , "deleted" },
195
207
},
196
208
ExpectedParams : idpsync.OrganizationParams {
197
209
SyncEntitled : true ,
@@ -204,11 +216,11 @@ func TestOrganizationSync(t *testing.T) {
204
216
})
205
217
dbgen .OrganizationMember (t , db , database.OrganizationMember {
206
218
UserID : user .ID ,
207
- OrganizationID : one .ID ,
219
+ OrganizationID : one .Org . ID ,
208
220
})
209
221
},
210
222
Sync : ExpectedUser {
211
- Organizations : []uuid.UUID {def .ID , one .ID , two .ID , three .ID },
223
+ Organizations : []uuid.UUID {def .ID , one .Org . ID , two .Org . ID , three . Org .ID },
212
224
},
213
225
},
214
226
},
0 commit comments