Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.23.0
go 1.24.0

toolchain go1.24.2

Expand Down
84 changes: 31 additions & 53 deletions service/authorization/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ func Test_GetDecisionsAllOf_Pass(t *testing.T) {
},
}

ctxb := context.Background()

testrego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -256,7 +254,7 @@ func Test_GetDecisionsAllOf_Pass(t *testing.T) {
))

// Run evaluation.
prepared, err := testrego.PrepareForEval(ctxb)
prepared, err := testrego.PrepareForEval(t.Context())
require.NoError(t, err)

// set the request
Expand Down Expand Up @@ -289,7 +287,7 @@ func Test_GetDecisionsAllOf_Pass(t *testing.T) {
eval: prepared,
}

resp, err := as.GetDecisions(ctxb, &req)
resp, err := as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -351,12 +349,12 @@ func Test_GetDecisionsAllOf_Pass(t *testing.T) {
))

// Run evaluation.
prepared, err = testrego.PrepareForEval(ctxb)
prepared, err = testrego.PrepareForEval(t.Context())
require.NoError(t, err)

as.eval = prepared

resp, err = as.GetDecisions(ctxb, &req)
resp, err = as.GetDecisions(t.Context(), &req)
require.NoError(t, err)
assert.Len(t, resp.Msg.GetDecisionResponses(), 2)
assert.Equal(t, authorization.DecisionResponse_DECISION_PERMIT, resp.Msg.GetDecisionResponses()[0].GetDecision())
Expand Down Expand Up @@ -433,8 +431,6 @@ func Test_GetDecisions_AllOf_Fail(t *testing.T) {
},
}

ctxb := context.Background()

testrego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -443,7 +439,7 @@ func Test_GetDecisions_AllOf_Fail(t *testing.T) {
))

// Run evaluation.
prepared, err := testrego.PrepareForEval(ctxb)
prepared, err := testrego.PrepareForEval(t.Context())
require.NoError(t, err)

as := AuthorizationService{
Expand All @@ -454,7 +450,7 @@ func Test_GetDecisions_AllOf_Fail(t *testing.T) {
eval: prepared,
}

resp, err := as.GetDecisions(ctxb, &req)
resp, err := as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -509,8 +505,6 @@ func Test_GetDecisionsAllOfWithEnvironmental_Pass(t *testing.T) {
},
}

ctxb := context.Background()

testrego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -519,7 +513,7 @@ func Test_GetDecisionsAllOfWithEnvironmental_Pass(t *testing.T) {
))

// Run evaluation.
prepared, err := testrego.PrepareForEval(ctxb)
prepared, err := testrego.PrepareForEval(t.Context())
require.NoError(t, err)

// set the request
Expand Down Expand Up @@ -553,7 +547,7 @@ func Test_GetDecisionsAllOfWithEnvironmental_Pass(t *testing.T) {
eval: prepared,
}

resp, err := as.GetDecisions(ctxb, &req)
resp, err := as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -605,8 +599,6 @@ func Test_GetDecisionsAllOfWithEnvironmental_Fail(t *testing.T) {
},
}

ctxb := context.Background()

testrego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -615,7 +607,7 @@ func Test_GetDecisionsAllOfWithEnvironmental_Fail(t *testing.T) {
))

// Run evaluation.
prepared, err := testrego.PrepareForEval(ctxb)
prepared, err := testrego.PrepareForEval(t.Context())
require.NoError(t, err)

// set the request
Expand Down Expand Up @@ -649,7 +641,7 @@ func Test_GetDecisionsAllOfWithEnvironmental_Fail(t *testing.T) {
eval: prepared,
}

resp, err := as.GetDecisions(ctxb, &req)
resp, err := as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -702,8 +694,6 @@ func Test_GetEntitlementsSimple(t *testing.T) {
},
}

ctxb := context.Background()

rego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -712,7 +702,7 @@ func Test_GetEntitlementsSimple(t *testing.T) {
))

// Run evaluation.
prepared, err := rego.PrepareForEval(ctxb)
prepared, err := rego.PrepareForEval(t.Context())
require.NoError(t, err)

as := AuthorizationService{
Expand All @@ -730,7 +720,7 @@ func Test_GetEntitlementsSimple(t *testing.T) {
},
}

resp, err := as.GetEntitlements(ctxb, &req)
resp, err := as.GetEntitlements(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -775,8 +765,6 @@ func Test_GetEntitlementsFqnCasing(t *testing.T) {
},
}

ctxb := context.Background()

rego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -785,7 +773,7 @@ func Test_GetEntitlementsFqnCasing(t *testing.T) {
))

// Run evaluation.
prepared, err := rego.PrepareForEval(ctxb)
prepared, err := rego.PrepareForEval(t.Context())
require.NoError(t, err)

as := AuthorizationService{
Expand All @@ -808,7 +796,7 @@ func Test_GetEntitlementsFqnCasing(t *testing.T) {
assert.Equal(t, fqn, strings.ToLower(fqn))
}

resp, err := as.GetEntitlements(ctxb, &req)
resp, err := as.GetEntitlements(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -853,8 +841,6 @@ func Test_GetEntitlements_HandlesPagination(t *testing.T) {
},
}

ctxb := context.Background()

rego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -863,7 +849,7 @@ func Test_GetEntitlements_HandlesPagination(t *testing.T) {
))

// Run evaluation.
prepared, err := rego.PrepareForEval(ctxb)
prepared, err := rego.PrepareForEval(t.Context())
require.NoError(t, err)

as := AuthorizationService{
Expand All @@ -887,7 +873,7 @@ func Test_GetEntitlements_HandlesPagination(t *testing.T) {
assert.Equal(t, fqn, strings.ToLower(fqn))
}

resp, err := as.GetEntitlements(ctxb, &req)
resp, err := as.GetEntitlements(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -946,8 +932,6 @@ func Test_GetEntitlementsWithComprehensiveHierarchy(t *testing.T) {
},
}

ctxb := context.Background()

rego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -956,7 +940,7 @@ func Test_GetEntitlementsWithComprehensiveHierarchy(t *testing.T) {
))

// Run evaluation.
prepared, err := rego.PrepareForEval(ctxb)
prepared, err := rego.PrepareForEval(t.Context())
require.NoError(t, err)
as := AuthorizationService{
logger: logger, sdk: &otdf.SDK{
Expand All @@ -975,7 +959,7 @@ func Test_GetEntitlementsWithComprehensiveHierarchy(t *testing.T) {
},
}

resp, err := as.GetEntitlements(ctxb, &req)
resp, err := as.GetEntitlements(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -1186,8 +1170,6 @@ func Test_GetDecisions_RA_FQN_Edge_Cases(t *testing.T) {
},
}

ctxb := context.Background()

testrego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -1196,7 +1178,7 @@ func Test_GetDecisions_RA_FQN_Edge_Cases(t *testing.T) {
))

// Run evaluation.
prepared, err := testrego.PrepareForEval(ctxb)
prepared, err := testrego.PrepareForEval(t.Context())
require.NoError(t, err)

as := AuthorizationService{
Expand Down Expand Up @@ -1235,7 +1217,7 @@ func Test_GetDecisions_RA_FQN_Edge_Cases(t *testing.T) {
},
}

resp, err := as.GetDecisions(ctxb, &req)
resp, err := as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -1271,7 +1253,7 @@ func Test_GetDecisions_RA_FQN_Edge_Cases(t *testing.T) {
},
}

resp, err = as.GetDecisions(ctxb, &req)
resp, err = as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -1307,7 +1289,7 @@ func Test_GetDecisions_RA_FQN_Edge_Cases(t *testing.T) {
},
}

resp, err = as.GetDecisions(ctxb, &req)
resp, err = as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -1358,8 +1340,6 @@ func Test_GetDecisionsAllOf_Pass_EC_RA_Length_Mismatch(t *testing.T) {
},
}

ctxb := context.Background()

/////// TEST1: Three entity chains, one resource attribute ///////
testrego := rego.New(
rego.Query("data.example.p"),
Expand All @@ -1369,7 +1349,7 @@ func Test_GetDecisionsAllOf_Pass_EC_RA_Length_Mismatch(t *testing.T) {
))

// Run evaluation.
prepared, err := testrego.PrepareForEval(ctxb)
prepared, err := testrego.PrepareForEval(t.Context())
require.NoError(t, err)

// set the request
Expand Down Expand Up @@ -1414,7 +1394,7 @@ func Test_GetDecisionsAllOf_Pass_EC_RA_Length_Mismatch(t *testing.T) {
eval: prepared,
}

resp, err := as.GetDecisions(ctxb, &req)
resp, err := as.GetDecisions(t.Context(), &req)

require.NoError(t, err)
assert.NotNil(t, resp)
Expand Down Expand Up @@ -1487,12 +1467,12 @@ func Test_GetDecisionsAllOf_Pass_EC_RA_Length_Mismatch(t *testing.T) {
))

// Run evaluation.
prepared, err = testrego.PrepareForEval(ctxb)
prepared, err = testrego.PrepareForEval(t.Context())
require.NoError(t, err)

as.eval = prepared

resp, err = as.GetDecisions(ctxb, &req)
resp, err = as.GetDecisions(t.Context(), &req)
require.NoError(t, err)
assert.Len(t, resp.Msg.GetDecisionResponses(), 6)

Expand Down Expand Up @@ -1556,12 +1536,12 @@ func Test_GetDecisionsAllOf_Pass_EC_RA_Length_Mismatch(t *testing.T) {
))

// Run evaluation.
prepared, err = testrego.PrepareForEval(ctxb)
prepared, err = testrego.PrepareForEval(t.Context())
require.NoError(t, err)

as.eval = prepared

resp, err = as.GetDecisions(ctxb, &req)
resp, err = as.GetDecisions(t.Context(), &req)
require.NoError(t, err)
assert.Len(t, resp.Msg.GetDecisionResponses(), 3)
assert.Equal(t, "ec1", resp.Msg.GetDecisionResponses()[0].GetEntityChainId())
Expand Down Expand Up @@ -1605,7 +1585,7 @@ func Test_GetDecisionsAllOf_Pass_EC_RA_Length_Mismatch(t *testing.T) {
},
}

resp, err = as.GetDecisions(ctxb, &req)
resp, err = as.GetDecisions(t.Context(), &req)
require.NoError(t, err)
assert.Len(t, resp.Msg.GetDecisionResponses(), 6)
assert.Equal(t, "ec1", resp.Msg.GetDecisionResponses()[0].GetEntityChainId())
Expand Down Expand Up @@ -1671,8 +1651,6 @@ func Test_GetDecisions_Empty_EC_RA(t *testing.T) {
},
}

ctxb := context.Background()

testrego := rego.New(
rego.Query("data.example.p"),
rego.Module("example.rego",
Expand All @@ -1681,7 +1659,7 @@ func Test_GetDecisions_Empty_EC_RA(t *testing.T) {
))

// Run evaluation.
prepared, err := testrego.PrepareForEval(ctxb)
prepared, err := testrego.PrepareForEval(t.Context())
require.NoError(t, err)

as := AuthorizationService{
Expand Down Expand Up @@ -1814,7 +1792,7 @@ func Test_GetDecisions_Empty_EC_RA(t *testing.T) {
///////////// Run tests /////////////////////
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
resp, err := as.GetDecisions(ctxb, &tc.req)
resp, err := as.GetDecisions(t.Context(), &tc.req)
require.NoError(t, err)
assert.NotNil(t, resp)
assert.Len(t, resp.Msg.GetDecisionResponses(), tc.numDecisions)
Expand Down
Loading
Loading