当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
15 Star 22 Fork 17

openGauss/openGauss-connector-go-pq
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ssl_permissions_test.go 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
//go:build !windows
// +build !windows
package pq
import (
"os"
"syscall"
"testing"
"time"
)
type stat_t_wrapper struct {
stat syscall.Stat_t
}
func (stat_t *stat_t_wrapper) Name() string {
return "pem.key"
}
func (stat_t *stat_t_wrapper) Size() int64 {
return int64(100)
}
func (stat_t *stat_t_wrapper) Mode() os.FileMode {
return os.FileMode(stat_t.stat.Mode)
}
func (stat_t *stat_t_wrapper) ModTime() time.Time {
return time.Now()
}
func (stat_t *stat_t_wrapper) IsDir() bool {
return true
}
func (stat_t *stat_t_wrapper) Sys() interface{} {
return &stat_t.stat
}
func TestHasCorrectRootGroupPermissions(t *testing.T) {
currentUID := uint32(os.Getuid())
currentGID := uint32(os.Getgid())
testData := []struct {
expectedError error
stat syscall.Stat_t
}{
{
expectedError: nil,
stat: syscall.Stat_t{
Mode: 0600,
Uid: currentUID,
Gid: currentGID,
},
},
{
expectedError: nil,
stat: syscall.Stat_t{
Mode: 0640,
Uid: 0,
Gid: currentGID,
},
},
{
expectedError: errSSLKeyHasUnacceptableUserPermissions,
stat: syscall.Stat_t{
Mode: 0666,
Uid: currentUID,
Gid: currentGID,
},
},
{
expectedError: errSSLKeyHasUnacceptableRootPermissions,
stat: syscall.Stat_t{
Mode: 0666,
Uid: 0,
Gid: currentGID,
},
},
}
for _, test := range testData {
wrapper := &stat_t_wrapper{
stat: test.stat,
}
if test.expectedError != hasCorrectPermissions(wrapper) {
if test.expectedError == nil {
t.Errorf(
"file owned by %d:%d with %s should not have failed check with error \"%s\"",
test.stat.Uid,
test.stat.Gid,
wrapper.Mode(),
hasCorrectPermissions(wrapper),
)
continue
}
t.Errorf(
"file owned by %d:%d with %s, expected \"%s\", got \"%s\"",
test.stat.Uid,
test.stat.Gid,
wrapper.Mode(),
test.expectedError,
hasCorrectPermissions(wrapper),
)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/opengauss/openGauss-connector-go-pq.git
git@gitee.com:opengauss/openGauss-connector-go-pq.git
opengauss
openGauss-connector-go-pq
openGauss-connector-go-pq
master

搜索帮助