From 6ea9b1ae1891c399570312b167878cc22798ea73 Mon Sep 17 00:00:00 2001 From: Claudio Beatrice Date: Sat, 26 Oct 2024 15:45:59 +0200 Subject: [PATCH] fix: rework permission tests to work around git limitations in permissions storage --- .../arch/file/expect/have_permissions_test.go | 28 +++++++++---------- .../file/expect/test/permissions/0700.txt | 1 - .../file/expect/test/permissions/0755.txt | 1 + 3 files changed, 15 insertions(+), 15 deletions(-) delete mode 100755 internal/arch/file/expect/test/permissions/0700.txt create mode 100755 internal/arch/file/expect/test/permissions/0755.txt diff --git a/internal/arch/file/expect/have_permissions_test.go b/internal/arch/file/expect/have_permissions_test.go index 53a8c6a..fe9cec5 100644 --- a/internal/arch/file/expect/have_permissions_test.go +++ b/internal/arch/file/expect/have_permissions_test.go @@ -31,7 +31,7 @@ func Test_HavePermissions(t *testing.T) { }{ { desc: "wrong permissions string", - ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0700.txt")), + ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0755.txt")), permissions: "foobarbaz-", want: nil, wantErrs: []error{expect.ErrInvalidPermissions}, @@ -43,9 +43,9 @@ func Test_HavePermissions(t *testing.T) { want: nil, }, { - desc: "permissions of file '0700.txt' match expected one", - ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0700.txt")), - permissions: "-rwx------", + desc: "permissions of file '0755.txt' match expected one", + ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0755.txt")), + permissions: "-rwxr-xr-x", want: nil, }, { @@ -59,11 +59,11 @@ func Test_HavePermissions(t *testing.T) { }, }, { - desc: "permissions of file '0700.txt' do not match expected one", - ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0700.txt")), + desc: "permissions of file '0755.txt' do not match expected one", + ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0755.txt")), permissions: "-rwxrwxrwx", want: []rule.CoreViolation{ - rule.NewCoreViolation("file '0700.txt' does not have permissions matching '-rwxrwxrwx', '-rwx------' found"), + rule.NewCoreViolation("file '0755.txt' does not have permissions matching '-rwxrwxrwx', '-rwxr-xr-x' found"), }, }, { @@ -76,12 +76,12 @@ func Test_HavePermissions(t *testing.T) { }, }, { - desc: "negated: permissions of file '0700.txt' match expected one", - ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0700.txt")), - permissions: "-rwx------", + desc: "negated: permissions of file '0755.txt' match expected one", + ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0755.txt")), + permissions: "-rwxr-xr-x", options: []expect.Option{expect.Negated{}}, want: []rule.CoreViolation{ - rule.NewCoreViolation("file '0700.txt' does have permissions matching '-rwx------', '-rwx------' found"), + rule.NewCoreViolation("file '0755.txt' does have permissions matching '-rwxr-xr-x', '-rwxr-xr-x' found"), }, }, { @@ -92,9 +92,9 @@ func Test_HavePermissions(t *testing.T) { want: nil, }, { - desc: "negated: permissions of file '0700.txt' do not match expected one", - ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0700.txt")), - permissions: "-rwxrwxrwx", + desc: "negated: permissions of file '0755.txt' do not match expected one", + ruleBuilder: file.One(filepath.Join(basePath, "test/permissions/0755.txt")), + permissions: "-rw-r--r--", options: []expect.Option{expect.Negated{}}, want: nil, }, diff --git a/internal/arch/file/expect/test/permissions/0700.txt b/internal/arch/file/expect/test/permissions/0700.txt deleted file mode 100755 index e9745d1..0000000 --- a/internal/arch/file/expect/test/permissions/0700.txt +++ /dev/null @@ -1 +0,0 @@ -0700 diff --git a/internal/arch/file/expect/test/permissions/0755.txt b/internal/arch/file/expect/test/permissions/0755.txt new file mode 100755 index 0000000..96ae912 --- /dev/null +++ b/internal/arch/file/expect/test/permissions/0755.txt @@ -0,0 +1 @@ +0755