Skip to content

Comments

refactor: test harness for areas touched for ROX-33014#19156

Draft
rhybrillou wants to merge 4 commits intomasterfrom
master-yann/ROX-33014/base_test_coverage
Draft

refactor: test harness for areas touched for ROX-33014#19156
rhybrillou wants to merge 4 commits intomasterfrom
master-yann/ROX-33014/base_test_coverage

Conversation

@rhybrillou
Copy link
Contributor

Description

change me!

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

change me!

@openshift-ci
Copy link

openshift-ci bot commented Feb 24, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In InternalRole.GetPermissions, you rely on storage.Access_value[access] returning the zero value for unknown access strings; consider doing an explicit map lookup and defaulting to Access_NO_ACCESS for clarity and to avoid surprises if the enum map ever changes.
  • In InternalRole.GetAccessScope, a ClusterScope with ClusterFullAccess set but an empty ClusterName will produce an empty cluster entry in IncludedClusters; consider skipping or validating such entries to avoid constructing malformed scopes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `InternalRole.GetPermissions`, you rely on `storage.Access_value[access]` returning the zero value for unknown access strings; consider doing an explicit map lookup and defaulting to `Access_NO_ACCESS` for clarity and to avoid surprises if the enum map ever changes.
- In `InternalRole.GetAccessScope`, a `ClusterScope` with `ClusterFullAccess` set but an empty `ClusterName` will produce an empty cluster entry in `IncludedClusters`; consider skipping or validating such entries to avoid constructing malformed scopes.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@rhacs-bot
Copy link
Contributor

rhacs-bot commented Feb 24, 2026

Images are ready for the commit at 9faf904.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-130-g9faf904f9a.

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

❌ Patch coverage is 90.47619% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.49%. Comparing base (c1cc0c5) to head (9faf904).
⚠️ Report is 43 commits behind head on master.

Files with missing lines Patch % Lines
pkg/auth/tokens/internal_role.go 90.47% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19156      +/-   ##
==========================================
- Coverage   49.51%   49.49%   -0.02%     
==========================================
  Files        2669     2683      +14     
  Lines      201479   202076     +597     
==========================================
+ Hits        99753   100013     +260     
- Misses      94278    94603     +325     
- Partials     7448     7460      +12     
Flag Coverage Δ
go-unit-tests 49.49% <90.47%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pkg/grpc/authn/tokenbased/extractor_test.go" line_range="103-101" />
<code_context>
+	authProvider authproviders.Provider
+}
+
+func TestExtractorIdentityForRequest(t *testing.T) {
+
+}
+
+func TestExtractorWithRoleNames(t *testing.T) {
</code_context>
<issue_to_address>
**issue (testing):** Implement or remove the empty TestExtractorIdentityForRequest test

This test is currently empty and doesn’t exercise `extractor.IdentityForRequest`. To avoid misleading coverage, either remove it or add meaningful cases (e.g., no token, malformed token, valid internal-role token, valid external-user token, multiple auth providers). Having at least one happy-path and key error-path case will ensure `IdentityForRequest` is covered at an integration level.
</issue_to_address>

### Comment 2
<location path="pkg/grpc/authn/tokenbased/extractor_test.go" line_range="123-129" />
<code_context>
+	for name, tc := range map[string]struct {
</code_context>
<issue_to_address>
**suggestion (testing):** Add a test case for external-user tokens with more than one source

In `TestExtractorWithExternalUser`, we only test the error for **no sources**, but not for **multiple sources**. Please add a table entry where `Sources` has length > 1 and assert we get the same "external user tokens must originate from exactly one source" error, so refactors can’t accidentally allow multi-source external-user tokens.

```suggestion
	for name, tc := range map[string]struct {
		testToken            *tokens.TokenInfo
		roleNames            []string
		setupMocks           func(*testExtractor)
		expectedErrorMessage string
	}{
		"Error: external user token with multiple sources": {
			testToken: &tokens.TokenInfo{
				Claims: buildRoleNamesClaims(
					testName,
					testSubject,
					testID,
					[]string{roleName1},
					testExpiresAt,
				),
				// Multiple sources should trigger:
				// "external user tokens must originate from exactly one source"
				Sources: []tokens.Source{
					mockSource,
					mockSource,
				},
			},
			// No special mocks required; the extractor should fail on validation
			setupMocks: func(te *testExtractor) {},
			expectedErrorMessage: "external user tokens must originate from exactly one source",
		},
		"Error: Role store GetAndResolveRole fails": {
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

attributes map[string][]string
expiry time.Time
authProvider authproviders.Provider
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (testing): Implement or remove the empty TestExtractorIdentityForRequest test

This test is currently empty and doesn’t exercise extractor.IdentityForRequest. To avoid misleading coverage, either remove it or add meaningful cases (e.g., no token, malformed token, valid internal-role token, valid external-user token, multiple auth providers). Having at least one happy-path and key error-path case will ensure IdentityForRequest is covered at an integration level.

Comment on lines +123 to +129
for name, tc := range map[string]struct {
testToken *tokens.TokenInfo
roleNames []string
setupMocks func(*testExtractor)
expectedErrorMessage string
}{
"Error: Role store GetAndResolveRole fails": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Add a test case for external-user tokens with more than one source

In TestExtractorWithExternalUser, we only test the error for no sources, but not for multiple sources. Please add a table entry where Sources has length > 1 and assert we get the same "external user tokens must originate from exactly one source" error, so refactors can’t accidentally allow multi-source external-user tokens.

Suggested change
for name, tc := range map[string]struct {
testToken *tokens.TokenInfo
roleNames []string
setupMocks func(*testExtractor)
expectedErrorMessage string
}{
"Error: Role store GetAndResolveRole fails": {
for name, tc := range map[string]struct {
testToken *tokens.TokenInfo
roleNames []string
setupMocks func(*testExtractor)
expectedErrorMessage string
}{
"Error: external user token with multiple sources": {
testToken: &tokens.TokenInfo{
Claims: buildRoleNamesClaims(
testName,
testSubject,
testID,
[]string{roleName1},
testExpiresAt,
),
// Multiple sources should trigger:
// "external user tokens must originate from exactly one source"
Sources: []tokens.Source{
mockSource,
mockSource,
},
},
// No special mocks required; the extractor should fail on validation
setupMocks: func(te *testExtractor) {},
expectedErrorMessage: "external user tokens must originate from exactly one source",
},
"Error: Role store GetAndResolveRole fails": {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants