Skip to content

Commit c1e6d20

Browse files
committed
avoid tenancy checks in the queues
1 parent e3d487f commit c1e6d20

File tree

4 files changed

+1
-118
lines changed

4 files changed

+1
-118
lines changed

queue/publisher.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ func (p *publisher) Publish(ctx context.Context, payload any, headers ...map[str
5151
metadata = localization.ToMap(metadata, language)
5252
}
5353

54-
metadata = security.SkipTenancyChecksToMap(ctx, metadata)
55-
5654
message, err := internal.Marshal(payload)
5755
if err != nil {
5856
return err

queue/subscriber.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (s *subscriber) processReceivedMessage(ctx context.Context, msg *pubsub.Mes
218218

219219
var metadata propagation.MapCarrier = msg.Metadata
220220

221-
pCtx := security.SkipTenancyChecksFromMap(jobCtx, metadata)
221+
pCtx := security.SkipTenancyChecksOnClaims(jobCtx)
222222

223223
authClaim := security.ClaimsFromMap(metadata)
224224
if authClaim != nil {

security/security_claims.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,6 @@ func SkipTenancyChecksOnClaims(ctx context.Context) context.Context {
242242
return context.WithValue(ctx, ctxKeySkipTenancyCheckOnClaim, true)
243243
}
244244

245-
func SkipTenancyChecksFromMap(ctx context.Context, m map[string]string) context.Context {
246-
check, ok := m["skip_tenancy_check"]
247-
if ok && check == "true" {
248-
return SkipTenancyChecksOnClaims(ctx)
249-
}
250-
251-
return ctx
252-
}
253-
254-
func SkipTenancyChecksToMap(ctx context.Context, m map[string]string) map[string]string {
255-
if !IsTenancyChecksOnClaimSkipped(ctx) {
256-
m["skip_tenancy_check"] = "true"
257-
}
258-
return m
259-
}
260-
261245
func IsTenancyChecksOnClaimSkipped(ctx context.Context) bool {
262246
isSkipped, ok := ctx.Value(ctxKeySkipTenancyCheckOnClaim).(bool)
263247
if !ok {

security/security_claims_test.go

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -254,85 +254,6 @@ func (s *AuthenticationTestSuite) TestTenancySkipFunctions() {
254254
setup func(context.Context, map[string]string) (context.Context, map[string]string)
255255
checkResult func(*testing.T, context.Context, map[string]string)
256256
}{
257-
{
258-
name: "SkipTenancyChecksFromMap with skip_tenancy_check=true should set skip flag",
259-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
260-
m["skip_tenancy_check"] = "true"
261-
ctx = security.SkipTenancyChecksFromMap(ctx, m)
262-
return ctx, m
263-
},
264-
checkResult: func(t *testing.T, ctx context.Context, _ map[string]string) {
265-
require.True(t, security.IsTenancyChecksOnClaimSkipped(ctx), "tenancy checks should be skipped")
266-
},
267-
},
268-
{
269-
name: "SkipTenancyChecksFromMap with skip_tenancy_check=false should not set skip flag",
270-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
271-
m["skip_tenancy_check"] = "false"
272-
ctx = security.SkipTenancyChecksFromMap(ctx, m)
273-
return ctx, m
274-
},
275-
checkResult: func(t *testing.T, ctx context.Context, _ map[string]string) {
276-
require.False(t, security.IsTenancyChecksOnClaimSkipped(ctx), "tenancy checks should not be skipped")
277-
},
278-
},
279-
{
280-
name: "SkipTenancyChecksFromMap without skip_tenancy_check should not set skip flag",
281-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
282-
ctx = security.SkipTenancyChecksFromMap(ctx, m)
283-
return ctx, m
284-
},
285-
checkResult: func(t *testing.T, ctx context.Context, _ map[string]string) {
286-
require.False(t, security.IsTenancyChecksOnClaimSkipped(ctx), "tenancy checks should not be skipped")
287-
},
288-
},
289-
{
290-
name: "SkipTenancyChecksFromMap with other values should not set skip flag",
291-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
292-
m["skip_tenancy_check"] = "maybe"
293-
m["other_key"] = "value"
294-
ctx = security.SkipTenancyChecksFromMap(ctx, m)
295-
return ctx, m
296-
},
297-
checkResult: func(t *testing.T, ctx context.Context, _ map[string]string) {
298-
require.False(t, security.IsTenancyChecksOnClaimSkipped(ctx), "tenancy checks should not be skipped")
299-
},
300-
},
301-
{
302-
name: "SkipTenancyChecksToMap with skip flag should not set skip_tenancy_check in map",
303-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
304-
ctx = security.SkipTenancyChecksOnClaims(ctx)
305-
m = security.SkipTenancyChecksToMap(ctx, m)
306-
return ctx, m
307-
},
308-
checkResult: func(t *testing.T, ctx context.Context, m map[string]string) {
309-
require.True(t, security.IsTenancyChecksOnClaimSkipped(ctx), "tenancy checks should be skipped")
310-
require.NotContains(t, m, "skip_tenancy_check", "map should not contain skip_tenancy_check key")
311-
},
312-
},
313-
{
314-
name: "SkipTenancyChecksToMap without skip flag should set skip_tenancy_check=true in map",
315-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
316-
m = security.SkipTenancyChecksToMap(ctx, m)
317-
return ctx, m
318-
},
319-
checkResult: func(t *testing.T, ctx context.Context, m map[string]string) {
320-
require.False(t, security.IsTenancyChecksOnClaimSkipped(ctx), "tenancy checks should not be skipped")
321-
require.Equal(t, "true", m["skip_tenancy_check"], "map should contain skip_tenancy_check=true")
322-
},
323-
},
324-
{
325-
name: "SkipTenancyChecksToMap preserves existing map values",
326-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
327-
m["existing_key"] = "existing_value"
328-
m = security.SkipTenancyChecksToMap(ctx, m)
329-
return ctx, m
330-
},
331-
checkResult: func(t *testing.T, _ context.Context, m map[string]string) {
332-
require.Equal(t, "existing_value", m["existing_key"], "existing map values should be preserved")
333-
require.Equal(t, "true", m["skip_tenancy_check"], "skip_tenancy_check should be set to true")
334-
},
335-
},
336257
{
337258
name: "IsTenancyChecksOnClaimSkipped with skip flag returns true",
338259
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
@@ -384,26 +305,6 @@ func (s *AuthenticationTestSuite) TestTenancySkipFunctions() {
384305
)
385306
},
386307
},
387-
{
388-
name: "Round trip: FromMap -> ToMap preserves skip state",
389-
setup: func(ctx context.Context, m map[string]string) (context.Context, map[string]string) {
390-
m["skip_tenancy_check"] = "true"
391-
ctx = security.SkipTenancyChecksFromMap(ctx, m)
392-
// Clear the original map and recreate it
393-
newMap := make(map[string]string)
394-
newMap = security.SkipTenancyChecksToMap(ctx, newMap)
395-
return ctx, newMap
396-
},
397-
checkResult: func(t *testing.T, ctx context.Context, m map[string]string) {
398-
require.True(t, security.IsTenancyChecksOnClaimSkipped(ctx), "context should have skip flag")
399-
require.NotContains(
400-
t,
401-
m,
402-
"skip_tenancy_check",
403-
"map should not contain skip_tenancy_check when context has skip flag",
404-
)
405-
},
406-
},
407308
}
408309

409310
for _, tc := range testCases {

0 commit comments

Comments
 (0)