Skip to content

Commit

Permalink
Add integration tests and refresh golden files
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielNagy committed Feb 6, 2024
1 parent 1b06084 commit 89d54ad
Show file tree
Hide file tree
Showing 170 changed files with 408 additions and 6 deletions.
15 changes: 12 additions & 3 deletions cmd/adsysd/integration_tests/adsys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,9 @@ client_timeout: %d`, socket, tc.timeout)), 0600)
type confOption func(*confOptions)

type confOptions struct {
adsysDir string
backend string
adsysDir string
backend string
detectCachedTicket bool
}

func confWithAdsysDir(adsysDir string) confOption {
Expand All @@ -212,6 +213,12 @@ func confWithBackend(backend string) confOption {
}
}

func confDetectCachedTicket(detectCachedTicket bool) confOption {
return func(o *confOptions) {
o.detectCachedTicket = detectCachedTicket
}
}

// createConf generates an adsys configuration in a temporary directory
// It will use adsysDir for socket, cache and run dir if provided.
func createConf(t *testing.T, opts ...confOption) (conf string) {
Expand Down Expand Up @@ -257,7 +264,9 @@ apparmor_dir: %s/apparmor.d/adsys
apparmorfs_dir: %s/apparmorfs
systemunit_dir: %s/systemd/system
global_trust_dir: %s/share/ca-certificates
`, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.backend, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir))
detect_cached_ticket: %t
`, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.backend, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.adsysDir, args.detectCachedTicket))

testutils.WriteFile(t, confFile, confData, os.ModePerm)
require.NoError(t, os.MkdirAll(filepath.Join(args.adsysDir, "dconf"), 0750), "Setup: should create dconf dir")
Expand Down
67 changes: 64 additions & 3 deletions cmd/adsysd/integration_tests/adsysctl_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,11 @@ func TestPolicyUpdate(t *testing.T) {
addPaths []string
readOnlyDirs []string
winbindMockBehavior string
krb5MockBehavior string
purge bool
missingCertmonger bool
noExportKrb5cc bool
detectCachedTicket bool

wantErr bool
}{
Expand All @@ -228,6 +231,33 @@ func TestPolicyUpdate(t *testing.T) {
backend: "winbind",
initState: "localhost-uptodate",
},
"Current user, KRB5CCNAME is not exported but present": {
initState: "localhost-uptodate",
noExportKrb5cc: true,
detectCachedTicket: true,
krb5MockBehavior: "return_ccache:%s",
},
"Current user, libkrb5 not used if KRB5CCNAME is present": {
initState: "localhost-uptodate",
detectCachedTicket: true,
krb5MockBehavior: "return_ccache:%s/maybebadvalue",
},
"Current user, libkrb5 not used if setting not enabled": {
initState: "localhost-uptodate",
krb5MockBehavior: "return_ccache:%s/maybebadvalue",
},
"Current user, librkb5 returns error but symlink is present": {
initState: "localhost-uptodate",
detectCachedTicket: true,
noExportKrb5cc: true,
krb5MockBehavior: "return_empty_ccache",
krb5ccNamesState: []krb5ccNamesWithState{
{
src: currentUser + ".krb5",
adsysSymlink: currentUser,
},
},
},
"Other user, first time": {
args: []string{"[email protected]", "[email protected]"},
initState: "localhost-uptodate",
Expand Down Expand Up @@ -871,6 +901,27 @@ func TestPolicyUpdate(t *testing.T) {
},
wantErr: true,
},
// Krb5 library error cases
"Error when libkrb5 ccache not present on disk": {
initState: "localhost-uptodate",
noExportKrb5cc: true,
detectCachedTicket: true,
krb5MockBehavior: "return_ccache:%s/not_present",
wantErr: true,
},
"Error when libkrb5 returns null value": {
initState: "localhost-uptodate",
noExportKrb5cc: true,
detectCachedTicket: true,
krb5MockBehavior: "return_null_ccache",
wantErr: true,
},
"Error when cached ticket setting not enabled": {
initState: "localhost-uptodate",
noExportKrb5cc: true,
krb5MockBehavior: "return_ccache:%s",
wantErr: true,
},
// Incompatible options
"Error on all and specific user requested": {
args: []string{"--all", "[email protected]", "[email protected]"},
Expand Down Expand Up @@ -1078,10 +1129,19 @@ func TestPolicyUpdate(t *testing.T) {
} else {
tc.krb5ccname = fmt.Sprintf("FILE:%s/%s", krb5dir, tc.krb5ccname)
}
t.Setenv("KRB5CCNAME", tc.krb5ccname)
if !tc.noExportKrb5cc {
t.Setenv("KRB5CCNAME", tc.krb5ccname)
}
}

if tc.krb5MockBehavior != "" {
if strings.Contains(tc.krb5MockBehavior, "return_ccache") {
tc.krb5MockBehavior = fmt.Sprintf(tc.krb5MockBehavior, tc.krb5ccname)
}
t.Setenv("ADSYS_KRB5_BEHAVIOR", tc.krb5MockBehavior)
}

conf := createConf(t, confWithAdsysDir(adsysDir), confWithBackend(tc.backend))
conf := createConf(t, confWithAdsysDir(adsysDir), confWithBackend(tc.backend), confDetectCachedTicket(tc.detectCachedTicket))
if tc.sssdConf != "" {
content, err := os.ReadFile(conf)
require.NoError(t, err, "Setup: can’t read configuration file")
Expand Down Expand Up @@ -1243,6 +1303,7 @@ func setupSubprocessForTest(t *testing.T, currentUser string, otherUsers ...stri
require.NoError(t, err, "libnss-wrapper is not installed on disk, either skip integration tests or install it")

mockWinbindLibPath := testutils.BuildWinbindMock(t, filepath.Join(rootProjectDir, "internal/ad/backends/winbind"))
mockKrb5LibPath := testutils.BuildKrb5Mock(t, filepath.Join(rootProjectDir, "internal/ad"))

var subArgs []string
// We are going to only reexec ourself: only take options (without -run)
Expand Down Expand Up @@ -1288,7 +1349,7 @@ func setupSubprocessForTest(t *testing.T, currentUser string, otherUsers ...stri
fmt.Sprintf("PYTHONPATH=%s", admock),

// override user and host database
fmt.Sprintf("LD_PRELOAD=libnss_wrapper.so:%s", mockWinbindLibPath),
fmt.Sprintf("LD_PRELOAD=libnss_wrapper.so:%s:%s", mockWinbindLibPath, mockKrb5LibPath),
fmt.Sprintf("NSS_WRAPPER_PASSWD=%s", passwd),
"NSS_WRAPPER_GROUP=/etc/group",
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/baz {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/bar {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
^[email protected] {
/etc/environment r,
@{HOMEDIRS}/.xauth* w,
/usr/bin/{,b,d,rb}ash Ux,
/usr/bin/{c,k,tc}sh Ux,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[org/gnome/desktop/background]
picture-options='stretched'
picture-uri='file:///usr/share/backgrounds/canonical.png'
[org/gnome/shell]
favorite-apps=['\'libreoffice-writer.desktop\'', '\'snap-store_ubuntu-software.desktop\'', '\'yelp.desktop']
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/org/gnome/desktop/background/picture-options
/org/gnome/desktop/background/picture-uri
/org/gnome/desktop/media-handling/automount
/org/gnome/shell/favorite-apps
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[org/gnome/desktop/interface]
clock-format='24h'
clock-show-date=false
clock-show-weekday=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/org/gnome/desktop/interface/clock-format
/org/gnome/desktop/interface/clock-show-date
/org/gnome/desktop/interface/clock-show-weekday
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:[email protected]
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TDB file
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is managed by adsys.
# Do not edit this file manually.
# Any changes will be overwritten.

[Configuration]
AdminIdentities=unix-group:sudo;unix-group:admin

[Configuration]
AdminIdentities=unix-user:[email protected];unix-group:[email protected]

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
final machine script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logoff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine shutdown
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine startup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subfolder other script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced script
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripts/script-machine-startup
scripts/subfolder/other-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
protocol://example.com/it/mount/path
protocol://example.com/all/other/mount/path
protocol://example.com/all/another/path
protocol://example.com/rnd/mount/path
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripts/otherfolder/script-user-logoff
scripts/subfolder/other-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scripts/script-user-logon
scripts/other-script-user-logon
scripts/script-user-logon
scripts/subfolder/other-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
final machine script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logoff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine shutdown
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine startup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subfolder other script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is managed by adsys.
# Do not edit this file manually.
# Any changes will be overwritten.

%admin ALL=(ALL) !ALL
%sudo ALL=(ALL:ALL) !ALL

"[email protected]" ALL=(ALL:ALL) ALL
"%[email protected]" ALL=(ALL:ALL) ALL

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/baz {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/bar {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
^[email protected] {
/etc/environment r,
@{HOMEDIRS}/.xauth* w,
/usr/bin/{,b,d,rb}ash Ux,
/usr/bin/{c,k,tc}sh Ux,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[org/gnome/desktop/background]
picture-options='stretched'
picture-uri='file:///usr/share/backgrounds/canonical.png'
[org/gnome/shell]
favorite-apps=['\'libreoffice-writer.desktop\'', '\'snap-store_ubuntu-software.desktop\'', '\'yelp.desktop']
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/org/gnome/desktop/background/picture-options
/org/gnome/desktop/background/picture-uri
/org/gnome/desktop/media-handling/automount
/org/gnome/shell/favorite-apps
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[org/gnome/desktop/interface]
clock-format='24h'
clock-show-date=false
clock-show-weekday=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/org/gnome/desktop/interface/clock-format
/org/gnome/desktop/interface/clock-show-date
/org/gnome/desktop/interface/clock-show-weekday
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:[email protected]
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
user-db:user
system-db:gdm
system-db:machine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TDB file
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is managed by adsys.
# Do not edit this file manually.
# Any changes will be overwritten.

[Configuration]
AdminIdentities=unix-group:sudo;unix-group:admin

[Configuration]
AdminIdentities=unix-user:[email protected];unix-group:[email protected]

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
final machine script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logoff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine shutdown
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine startup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subfolder other script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced script
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripts/script-machine-startup
scripts/subfolder/other-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
protocol://example.com/it/mount/path
protocol://example.com/all/other/mount/path
protocol://example.com/all/another/path
protocol://example.com/rnd/mount/path
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scripts/otherfolder/script-user-logoff
scripts/subfolder/other-script
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scripts/script-user-logon
scripts/other-script-user-logon
scripts/script-user-logon
scripts/subfolder/other-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
final machine script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logoff
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine shutdown
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script machine startup
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
script user logon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subfolder other script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced data
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unreferenced script
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file is managed by adsys.
# Do not edit this file manually.
# Any changes will be overwritten.

%admin ALL=(ALL) !ALL
%sudo ALL=(ALL:ALL) !ALL

"[email protected]" ALL=(ALL:ALL) ALL
"%[email protected]" ALL=(ALL:ALL) ALL

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/baz {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/bar {}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/usr/bin/foo {}
Loading

0 comments on commit 89d54ad

Please sign in to comment.