mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-09-05 20:07:25 +00:00
Co-authored-by: cyphercodes <cyphercodes@users.noreply.github.com>
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
// Copyright 2026 Woodpecker Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSetUnixSocketPermission(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
permission string
|
|
want os.FileMode
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "owner and group read write",
|
|
permission: "660",
|
|
want: 0o660,
|
|
},
|
|
{
|
|
name: "world read write",
|
|
permission: "666",
|
|
want: 0o666,
|
|
},
|
|
{
|
|
name: "rejects non-octal digits",
|
|
permission: "999",
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
path := t.TempDir() + "/socket"
|
|
require.NoError(t, os.WriteFile(path, []byte(""), 0o600))
|
|
|
|
err := setUnixSocketPermission(path, tt.permission)
|
|
if tt.wantErr {
|
|
require.Error(t, err)
|
|
return
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
info, err := os.Stat(path)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, tt.want, info.Mode().Perm())
|
|
})
|
|
}
|
|
}
|