Skip to content

Commit

Permalink
Update tests on windows to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
stvnrhodes committed Jun 5, 2023
1 parent 03285e5 commit aa3dbf3
Show file tree
Hide file tree
Showing 16 changed files with 208 additions and 92 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# We checksum this data in tests so we need the content to be
# identical across operating systems.
services/localfile/server/testdata/sum.data text eol=lf
31 changes: 8 additions & 23 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ package sansshell.authz
default allow = false
allow {
input.type = "LocalFile.ReadActionRequest"
input.message.file.filename = "/etc/hosts"
}
allow {
input.type = "LocalFile.ReadActionRequest"
input.message.file.filename = "/no-such-filename-for-sansshell-unittest"
input.type = "LocalFile.ReadActionRequest"
input.message.file.filename in [
"/etc/hosts",
"/no-such-filename-for-sansshell-unittest",
"C:\\Windows\\win.ini",
"C:\\no-such-filename-for-sansshell-unittest",
]
}
`
)
Expand Down Expand Up @@ -138,23 +139,7 @@ func TestRead(t *testing.T) {
testutil.FatalOnErr("Failed to dial bufnet", err, t)
t.Cleanup(func() { conn.Close() })

for _, tc := range []struct {
filename string
err string
}{
{
filename: "/etc/hosts",
err: "",
},
{
filename: "/no-such-filename-for-sansshell-unittest",
err: "no such file or directory",
},
{
filename: "/permission-denied-filename-for-sansshell-unittest",
err: "PermissionDenied",
},
} {
for _, tc := range readFileTestCases {
tc := tc
t.Run(tc.filename, func(t *testing.T) {
client := lfpb.NewLocalFileClient(conn)
Expand Down
21 changes: 21 additions & 0 deletions server/server_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build unix

package server

var readFileTestCases = []struct {
filename string
err string
}{
{
filename: "/etc/hosts",
err: "",
},
{
filename: "/no-such-filename-for-sansshell-unittest",
err: "no such file or directory",
},
{
filename: "/permission-denied-filename-for-sansshell-unittest",
err: "PermissionDenied",
},
}
21 changes: 21 additions & 0 deletions server/server_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build windows

package server

var readFileTestCases = []struct {
filename string
err string
}{
{
filename: "C:\\Windows\\win.ini",
err: "",
},
{
filename: "C:\\no-such-filename-for-sansshell-unittest",
err: "The system cannot find the file specified",
},
{
filename: "/permission-denied-filename-for-sansshell-unittest",
err: "PermissionDenied",
},
}
2 changes: 2 additions & 0 deletions services/fdb/server/conf_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unix

/* Copyright (c) 2019 Snowflake Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the
Expand Down
2 changes: 2 additions & 0 deletions services/fdb/server/fdbcli_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unix

/* Copyright (c) 2019 Snowflake Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the
Expand Down
2 changes: 2 additions & 0 deletions services/fdb/server/server_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build unix

/* Copyright (c) 2019 Snowflake Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the
Expand Down
6 changes: 5 additions & 1 deletion services/localfile/server/localfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"os"
"os/user"
"path/filepath"
"runtime"
"strconv"
"time"

Expand Down Expand Up @@ -318,6 +319,9 @@ func setupOutput(a *pb.FileAttributes) (*os.File, *immutableState, error) {
// to accidentally leave this in another otherwise default state.
// Except we don't trigger immutable now or we won't be able to write to it.
immutable, err := validateAndSetAttrs(f.Name(), a.Attributes, false)
if err != nil {
f.Close()
}
return f, immutable, err
}

Expand Down Expand Up @@ -630,7 +634,7 @@ func validateAndSetAttrs(filename string, attrs []*pb.FileAttribute, doImmutable
}
}

if uid != -1 || gid != -1 {
if runtime.GOOS != "windows" {
if err := chown(filename, uid, gid); err != nil {
return nil, status.Errorf(codes.Internal, "error from chown: %v", err)
}
Expand Down
6 changes: 4 additions & 2 deletions services/localfile/server/localfile_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ import (
pb "github.com/Snowflake-Labs/sansshell/services/localfile"
)

// osStat is the platform agnostic version which uses basic os.Stat.
var osStat = defaultOsStat

// defaultOsStat is the platform agnostic version which uses basic os.Stat.
// As a result immutable bits cannot be returned.
func osStat(path string, useLstat bool) (*pb.StatReply, error) {
func defaultOsStat(path string, useLstat bool) (*pb.StatReply, error) {
var stat fs.FileInfo
var err error
if useLstat {
Expand Down
Loading

0 comments on commit aa3dbf3

Please sign in to comment.