From 8ace13074f51e651f4f717c9929c5f5d95251914 Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 29 Mar 2026 14:54:31 +0200 Subject: [PATCH] Update CI pipeline to use Go 1.25.8, enhance Definition of Done with SonarQube checks, refactor SID allocation in Windows functions, and improve test coverage for JoiningSlash function. --- .drone.yml | 2 +- AGENTS.md | 4 ++++ docs/DEFINITION_OF_DONE.md | 4 ++++ os_windows.go | 18 +++++++++++------- os_windows_test.go | 20 ++++---------------- utils.go | 1 - utils_test.go | 20 ++++++++++++++------ 7 files changed, 38 insertions(+), 31 deletions(-) diff --git a/.drone.yml b/.drone.yml index 0cf4b3a..39db88c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,7 +4,7 @@ name: go-lib/util steps: - name: test - image: golang:1.18 + image: golang:1.25.8 commands: - go get ./... - go test ./... diff --git a/AGENTS.md b/AGENTS.md index 32da315..32fd1c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -69,6 +69,9 @@ The Definition of Done defines the minimum quality bar for every completed chang - No new blocking errors are introduced. - Known non-blocking warnings are acceptable only if unrelated to the change or documented. +1. SonarQube status +- No SonarQube errors are present. + 1. Documentation structure - Links to moved or newly added docs are valid. - Documentation structure remains consistent with project rules. @@ -81,4 +84,5 @@ The Definition of Done defines the minimum quality bar for every completed chang - [ ] Functionality is documented. - [ ] Documentation is in English. - [ ] Documentation is located under `docs/` (except `README.md` and `AGENTS.md`). +- [ ] No SonarQube errors are present. - [ ] No critical regressions found. diff --git a/docs/DEFINITION_OF_DONE.md b/docs/DEFINITION_OF_DONE.md index 884a425..a47d72f 100644 --- a/docs/DEFINITION_OF_DONE.md +++ b/docs/DEFINITION_OF_DONE.md @@ -32,6 +32,9 @@ This Definition of Done defines the minimum quality bar for every completed chan - No new blocking errors are introduced. - Known non-blocking warnings are acceptable only if unrelated to the change or documented. +1. SonarQube status +- No SonarQube errors are present. + 1. Documentation links and structure - Links to moved or newly added docs are valid. - Documentation structure remains consistent with project rules. @@ -45,4 +48,5 @@ This Definition of Done defines the minimum quality bar for every completed chan - [ ] Functionality is documented. - [ ] Documentation is in English. - [ ] Documentation is located under `docs/` (except `README.md` and `AGENTS.md`). +- [ ] No SonarQube errors are present. - [ ] No critical regressions found. diff --git a/os_windows.go b/os_windows.go index 4943a2e..7383ac8 100644 --- a/os_windows.go +++ b/os_windows.go @@ -13,6 +13,16 @@ import ( var ( allocateAndInitializeSid = windows.AllocateAndInitializeSid + allocateAdminGroupSid = func(sid **windows.SID) error { + return allocateAndInitializeSid( + &windows.SECURITY_NT_AUTHORITY, + 2, + windows.SECURITY_BUILTIN_DOMAIN_RID, + windows.DOMAIN_ALIAS_RID_ADMINS, + 0, 0, 0, 0, 0, 0, + sid, + ) + } freeSid = windows.FreeSid tokenIsMember = func(token windows.Token, sid *windows.SID) (bool, error) { return token.IsMember(sid) } fatalf = log.Fatalf @@ -27,13 +37,7 @@ func IsSuperUser() bool { // official windows documentation. The Go API for this is a // direct wrap around the official C++ API. // See https://docs.microsoft.com/en-us/windows/desktop/api/securitybaseapi/nf-securitybaseapi-checktokenmembership - err := allocateAndInitializeSid( - &windows.SECURITY_NT_AUTHORITY, - 2, - windows.SECURITY_BUILTIN_DOMAIN_RID, - windows.DOMAIN_ALIAS_RID_ADMINS, - 0, 0, 0, 0, 0, 0, - &sid) + err := allocateAdminGroupSid(&sid) if err != nil { fatalf("SID Error: %s", err) return false diff --git a/os_windows_test.go b/os_windows_test.go index f33a65a..6415230 100644 --- a/os_windows_test.go +++ b/os_windows_test.go @@ -13,31 +13,19 @@ import ( func TestIsSuperUser_SidAllocationError(t *testing.T) { Convey("IsSuperUser should return false when SID allocation fails", t, func() { - origAllocate := allocateAndInitializeSid + origAllocate := allocateAdminGroupSid origFatalf := fatalf defer func() { - allocateAndInitializeSid = origAllocate + allocateAdminGroupSid = origAllocate fatalf = origFatalf }() - allocateAndInitializeSid = func( - authority *windows.SidIdentifierAuthority, - subAuthorityCount byte, - subAuthority0 uint32, - subAuthority1 uint32, - subAuthority2 uint32, - subAuthority3 uint32, - subAuthority4 uint32, - subAuthority5 uint32, - subAuthority6 uint32, - subAuthority7 uint32, - sid **windows.SID, - ) error { + allocateAdminGroupSid = func(_ **windows.SID) error { return errors.New("forced sid allocation error") } fatalCalled := false - fatalf = func(format string, v ...interface{}) { + fatalf = func(_ string, _ ...interface{}) { fatalCalled = true } diff --git a/utils.go b/utils.go index c607d78..0601455 100644 --- a/utils.go +++ b/utils.go @@ -34,7 +34,6 @@ func joiningSlash(elem []string) string { } func singleJoiningSlash(a, b string) string { - filepath.Join(a, b) aslash := strings.HasSuffix(a, "/") bslash := strings.HasPrefix(b, "/") switch { diff --git a/utils_test.go b/utils_test.go index 1ba39da..cd06eb8 100644 --- a/utils_test.go +++ b/utils_test.go @@ -23,12 +23,20 @@ func TestFileExists(t *testing.T) { func TestJoiningSlash(t *testing.T) { Convey("JoiningSlash should combine URL-like segments safely", t, func() { - So(JoiningSlash("http://my.tld/docs/", "bla/", "blub/"), ShouldEqual, "http://my.tld/docs/bla/blub/") - So(JoiningSlash("http://my.tld", "bla", "blub"), ShouldEqual, "http://my.tld/bla/blub") - So(JoiningSlash("http://my.tld/", "bla", "blub"), ShouldEqual, "http://my.tld/bla/blub") - So(JoiningSlash("http://my.tld", "bla/", "blub"), ShouldEqual, "http://my.tld/bla/blub") - So(JoiningSlash("http://my.tld/docs", "bla/", "blub"), ShouldEqual, "http://my.tld/docs/bla/blub") - So(JoiningSlash("http://my.tld/docs/", "bla/", "blub"), ShouldEqual, "http://my.tld/docs/bla/blub") + const ( + baseURL = "http://my.tld" + docsURL = "http://my.tld/docs" + expectedRoot = "http://my.tld/bla/blub" + expectedDocs = "http://my.tld/docs/bla/blub" + expectedDocsS = "http://my.tld/docs/bla/blub/" + ) + + So(JoiningSlash(docsURL+"/", "bla/", "blub/"), ShouldEqual, expectedDocsS) + So(JoiningSlash(baseURL, "bla", "blub"), ShouldEqual, expectedRoot) + So(JoiningSlash(baseURL+"/", "bla", "blub"), ShouldEqual, expectedRoot) + So(JoiningSlash(baseURL, "bla/", "blub"), ShouldEqual, expectedRoot) + So(JoiningSlash(docsURL, "bla/", "blub"), ShouldEqual, expectedDocs) + So(JoiningSlash(docsURL+"/", "bla/", "blub"), ShouldEqual, expectedDocs) So(JoiningSlash("", "api", "v1"), ShouldEqual, "api/v1") So(JoiningSlash("", "", ""), ShouldEqual, "") })