Skip to content

Commit b5d955d

Browse files
Merge branch 'main' into adding-lint-commit-and-husky-to-root-configuration
Signed-off-by: Dibyanshu Pal Kushwaha <dibyanshupkushwaha@gmail.com>
2 parents f14d87b + b3b39c5 commit b5d955d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+4493
-3496
lines changed

.github/workflows/backend-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ jobs:
7676
rm ~/.config/Headlamp/kubeconfigs/config
7777
shell: bash
7878

79+
- name: Run fuzz tests
80+
run: npm run backend:fuzz
81+
shell: bash
82+
7983
- name: Upload coverage report as artifact
8084
id: upload-artifact
8185
uses: actions/upload-artifact@84480863f228bb9747b473957fcc9e309aa96097 # v4.4.2

.github/workflows/draft-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- name: Checkout code
23-
uses: actions/checkout@v4
23+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2424
with:
2525
fetch-depth: 0
2626

@@ -48,7 +48,7 @@ jobs:
4848
echo "EOF" >> $GITHUB_OUTPUT
4949
5050
- name: Create Release Coordination Issue
51-
uses: actions/github-script@v7
51+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
5252
with:
5353
github-token: ${{ github.token }}
5454
script: |

.github/workflows/helm-chart-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
with:
7777
config: .github/cr.yaml
7878
mark_as_latest: false # only headlamp is set to latest
79+
skip_existing: true # skip package upload if release already exists
7980

8081
- name: Push Charts to GHCR
8182
run: |

AGENTS.md

Lines changed: 367 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ backend-embed-linux-386:
194194
backend-test:
195195
cd backend && go test -v -p 1 ./...
196196

197+
.PHONY: backend-fuzz
198+
backend-fuzz:
199+
npm run backend:fuzz
200+
197201
.PHONY: backend-coverage
198202
backend-coverage:
199203
cd backend && go test -v -p 1 -coverprofile=coverage.out ./...

OWNERS_ALIASES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ aliases:
33
- joaquimrocha
44
- illume
55
- sniok
6+
- yolossn
67
headlamp-reviewers:
78
- joaquimrocha
89
- illume
910
- sniok
1011
- ashu8912
11-
- yolossn
1212
- vyncent-t
1313
- skoeva
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package auth_test
18+
19+
import (
20+
"regexp"
21+
"testing"
22+
"unicode/utf8"
23+
24+
"github.com/kubernetes-sigs/headlamp/backend/pkg/auth"
25+
)
26+
27+
// FuzzSanitizeClusterName tests the SanitizeClusterName function with various inputs
28+
// to ensure it handles edge cases, special characters, and maintains its invariants.
29+
func FuzzSanitizeClusterName(f *testing.F) {
30+
// Seed corpus with known interesting test cases
31+
f.Add("my-cluster")
32+
f.Add("my_cluster")
33+
f.Add("cluster123")
34+
f.Add("my-cluster@#$%")
35+
f.Add("")
36+
f.Add("very-long-cluster-name-that-exceeds-fifty-characters-limit")
37+
f.Add("special!@#$%^&*()chars")
38+
f.Add("unicode-日本語-cluster")
39+
f.Add("spaces in name")
40+
f.Add("trailing-dash-")
41+
f.Add("-leading-dash")
42+
f.Add("___underscores___")
43+
f.Add("UPPERCASE")
44+
f.Add("MixedCase123")
45+
46+
validCharsRegex := regexp.MustCompile(`^[a-zA-Z0-9\-_]*$`)
47+
48+
f.Fuzz(func(t *testing.T, input string) {
49+
result := auth.SanitizeClusterName(input)
50+
51+
// Invariant 1: Result should never be longer than 50 characters
52+
if len(result) > 50 {
53+
t.Errorf("SanitizeClusterName(%q) returned result with length %d, expected <= 50", input, len(result))
54+
}
55+
56+
// Invariant 2: Result should only contain alphanumeric characters, hyphens, and underscores
57+
if !validCharsRegex.MatchString(result) {
58+
t.Errorf("SanitizeClusterName(%q) = %q contains invalid characters", input, result)
59+
}
60+
61+
// Invariant 3: Result should be a valid UTF-8 string
62+
if !utf8.ValidString(result) {
63+
t.Errorf("SanitizeClusterName(%q) = %q is not valid UTF-8", input, result)
64+
}
65+
66+
// Invariant 4: If input is empty, result should be empty
67+
if input == "" && result != "" {
68+
t.Errorf("SanitizeClusterName(%q) = %q, expected empty string", input, result)
69+
}
70+
71+
// Invariant 5: Result should be idempotent - sanitizing the result again should give the same result
72+
result2 := auth.SanitizeClusterName(result)
73+
if result != result2 {
74+
t.Errorf("SanitizeClusterName is not idempotent: first=%q, second=%q", result, result2)
75+
}
76+
77+
// Invariant 6: Result length should never exceed input length (sanitization only removes characters)
78+
if len(input) > 0 && len(result) > len(input) {
79+
t.Errorf("SanitizeClusterName(%q) returned result longer than input: input_len=%d, result_len=%d",
80+
input, len(input), len(result))
81+
}
82+
})
83+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go test fuzz v1
2+
string("my-cluster@#$%")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go test fuzz v1
2+
string("very-long-cluster-name-that-exceeds-fifty-characters-limit")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
go test fuzz v1
2+
string("unicode-日本語-cluster")

0 commit comments

Comments
 (0)