Skip to content

Commit 281329e

Browse files
Update the test coverage
Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot) Assisted by [Claude](https://claude.ai)
1 parent 32e3322 commit 281329e

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

cla-backend-go/v2/sign/service.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3077,7 +3077,7 @@ func (s *service) checkCompanyCompliance(ctx context.Context, company *v1Models.
30773077
// Only an explicit clean/flagged is actionable. Any other status is ambiguous: block
30783078
// when required; otherwise honor the persisted sanction state without clearing or
30793079
// caching (never auto-clear an SSS-origin block on an unknown status).
3080-
if result.Status != sss.StatusClean && result.Status != sss.StatusFlagged {
3080+
if !sssStatusActionable(result.Status) {
30813081
return s.complianceUnavailable(f, company, fmt.Errorf("checkCompanyCompliance: unexpected SSS status %q for company %s", result.Status, company.CompanyID))
30823082
}
30833083

@@ -3137,6 +3137,13 @@ func (s *service) complianceUnavailable(f logrus.Fields, company *v1Models.Compa
31373137
return company.IsSanctioned, nil
31383138
}
31393139

3140+
// sssStatusActionable reports whether an SSS status is one checkCompanyCompliance can act
3141+
// on directly (clean or flagged). Any other (ambiguous/unknown) status must be treated as
3142+
// "no live result" rather than silently as clean.
3143+
func sssStatusActionable(status string) bool {
3144+
return status == sss.StatusClean || status == sss.StatusFlagged
3145+
}
3146+
31403147
// applyComplianceToModel updates the in-memory company model to reflect a compliance
31413148
// decision so downstream gates in the same request stay consistent with this check.
31423149
func (s *service) applyComplianceToModel(company *v1Models.Company, sanctioned bool) {

cla-backend-go/v2/sign/service_sss_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,27 @@ func TestComplianceUnavailableOptionalHonorsPersistedSanction(t *testing.T) {
119119
}
120120
}
121121

122+
// sssStatusActionable is the guard checkCompanyCompliance uses to route ambiguous statuses
123+
// to complianceUnavailable; flipping it is the regression that would let an unknown status
124+
// fall through to the clean/clear path.
125+
func TestSSSStatusActionable(t *testing.T) {
126+
cases := []struct {
127+
status string
128+
want bool
129+
}{
130+
{sss.StatusClean, true},
131+
{sss.StatusFlagged, true},
132+
{"pending", false},
133+
{"PENDING", false},
134+
{"", false},
135+
}
136+
for _, tc := range cases {
137+
if got := sssStatusActionable(tc.status); got != tc.want {
138+
t.Errorf("sssStatusActionable(%q) = %v, want %v", tc.status, got, tc.want)
139+
}
140+
}
141+
}
142+
122143
func TestCheckCompanyComplianceRequiredBlocksMissingExternalID(t *testing.T) {
123144
svc := &service{sssRequired: true, sssClient: newTestSSSClient(t)}
124145

0 commit comments

Comments
 (0)