mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
106 lines
4.1 KiB
Go
106 lines
4.1 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/models/perm"
|
|
"github.com/hanzoai/git/models/unit"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestActionsConfig(t *testing.T) {
|
|
cfg := &ActionsConfig{}
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
|
|
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{"test1.yaml"}, cfg.DisabledWorkflows)
|
|
|
|
cfg.EnableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{}, cfg.DisabledWorkflows)
|
|
|
|
cfg.EnableWorkflow("test1.yaml")
|
|
assert.Equal(t, []string{}, cfg.DisabledWorkflows)
|
|
|
|
cfg.DisableWorkflow("test1.yaml")
|
|
cfg.DisableWorkflow("test2.yaml")
|
|
cfg.DisableWorkflow("test3.yaml")
|
|
assert.Equal(t, "test1.yaml,test2.yaml,test3.yaml", strings.Join(cfg.DisabledWorkflows, ","))
|
|
}
|
|
|
|
func TestActionsConfigTokenPermissions(t *testing.T) {
|
|
t.Run("Default Permission Mode", func(t *testing.T) {
|
|
cfg := &ActionsConfig{TokenPermissionMode: "invalid-value"}
|
|
_ = cfg.FromDB(nil)
|
|
assert.Equal(t, ActionsTokenPermissionModePermissive, cfg.TokenPermissionMode)
|
|
assert.Equal(t, perm.AccessModeWrite, cfg.GetDefaultTokenPermissions().UnitAccessModes[unit.TypeCode])
|
|
})
|
|
|
|
t.Run("Explicit Permission Mode", func(t *testing.T) {
|
|
cfg := &ActionsConfig{
|
|
TokenPermissionMode: ActionsTokenPermissionModeRestricted,
|
|
}
|
|
assert.Equal(t, ActionsTokenPermissionModeRestricted, cfg.TokenPermissionMode)
|
|
})
|
|
|
|
t.Run("Effective Permissions - Permissive Mode", func(t *testing.T) {
|
|
cfg := &ActionsConfig{
|
|
TokenPermissionMode: ActionsTokenPermissionModePermissive,
|
|
}
|
|
defaultPerms := cfg.GetDefaultTokenPermissions()
|
|
perms := cfg.ClampPermissions(defaultPerms)
|
|
assert.Equal(t, perm.AccessModeWrite, perms.UnitAccessModes[unit.TypeCode])
|
|
assert.Equal(t, perm.AccessModeWrite, perms.UnitAccessModes[unit.TypeIssues])
|
|
assert.Equal(t, perm.AccessModeWrite, perms.UnitAccessModes[unit.TypePackages])
|
|
})
|
|
|
|
t.Run("Effective Permissions - Restricted Mode", func(t *testing.T) {
|
|
cfg := &ActionsConfig{
|
|
TokenPermissionMode: ActionsTokenPermissionModeRestricted,
|
|
}
|
|
defaultPerms := cfg.GetDefaultTokenPermissions()
|
|
perms := cfg.ClampPermissions(defaultPerms)
|
|
assert.Equal(t, perm.AccessModeRead, perms.UnitAccessModes[unit.TypeCode])
|
|
assert.Equal(t, perm.AccessModeNone, perms.UnitAccessModes[unit.TypeIssues])
|
|
assert.Equal(t, perm.AccessModeRead, perms.UnitAccessModes[unit.TypePackages])
|
|
})
|
|
|
|
t.Run("Clamp Permissions", func(t *testing.T) {
|
|
cfg := &ActionsConfig{
|
|
MaxTokenPermissions: &ActionsTokenPermissions{
|
|
UnitAccessModes: map[unit.Type]perm.AccessMode{
|
|
unit.TypeCode: perm.AccessModeRead,
|
|
unit.TypeIssues: perm.AccessModeWrite,
|
|
unit.TypePullRequests: perm.AccessModeRead,
|
|
unit.TypePackages: perm.AccessModeRead,
|
|
unit.TypeActions: perm.AccessModeNone,
|
|
unit.TypeWiki: perm.AccessModeWrite,
|
|
},
|
|
},
|
|
}
|
|
input := ActionsTokenPermissions{
|
|
UnitAccessModes: map[unit.Type]perm.AccessMode{
|
|
unit.TypeCode: perm.AccessModeWrite, // Should be clamped to Read
|
|
unit.TypeIssues: perm.AccessModeWrite, // Should stay Write
|
|
unit.TypePullRequests: perm.AccessModeWrite, // Should be clamped to Read
|
|
unit.TypePackages: perm.AccessModeWrite, // Should be clamped to Read
|
|
unit.TypeActions: perm.AccessModeRead, // Should be clamped to None
|
|
unit.TypeWiki: perm.AccessModeRead, // Should stay Read
|
|
},
|
|
}
|
|
clamped := cfg.ClampPermissions(input)
|
|
assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypeCode])
|
|
assert.Equal(t, perm.AccessModeWrite, clamped.UnitAccessModes[unit.TypeIssues])
|
|
assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypePullRequests])
|
|
assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypePackages])
|
|
assert.Equal(t, perm.AccessModeNone, clamped.UnitAccessModes[unit.TypeActions])
|
|
assert.Equal(t, perm.AccessModeRead, clamped.UnitAccessModes[unit.TypeWiki])
|
|
})
|
|
}
|