All checks were successful
		
		
	
	Test / Create distribution (push) Successful in 33s
				
			Test / Sandbox (push) Successful in 2m10s
				
			Test / Hakurei (push) Successful in 3m8s
				
			Test / Sandbox (race detector) (push) Successful in 3m58s
				
			Test / Hpkg (push) Successful in 4m3s
				
			Test / Hakurei (race detector) (push) Successful in 4m44s
				
			Test / Flake checks (push) Successful in 1m26s
				
			This should happen in hst since it requires no system state. Signed-off-by: Ophestra <cat@gensokyo.uk>
		
			
				
	
	
		
			101 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			101 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package hst_test
 | |
| 
 | |
| import (
 | |
| 	"reflect"
 | |
| 	"testing"
 | |
| 
 | |
| 	"hakurei.app/container/fhs"
 | |
| 	"hakurei.app/hst"
 | |
| )
 | |
| 
 | |
| func TestConfigValidate(t *testing.T) {
 | |
| 	t.Parallel()
 | |
| 
 | |
| 	testCases := []struct {
 | |
| 		name    string
 | |
| 		config  *hst.Config
 | |
| 		wantErr error
 | |
| 	}{
 | |
| 		{"nil", nil, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
 | |
| 			Msg: "invalid configuration"}},
 | |
| 		{"identity lower", &hst.Config{Identity: -1}, &hst.AppError{Step: "validate configuration", Err: hst.ErrIdentityBounds,
 | |
| 			Msg: "identity -1 out of range"}},
 | |
| 		{"identity upper", &hst.Config{Identity: 10000}, &hst.AppError{Step: "validate configuration", Err: hst.ErrIdentityBounds,
 | |
| 			Msg: "identity 10000 out of range"}},
 | |
| 		{"dbus session", &hst.Config{SessionBus: &hst.BusConfig{See: []string{""}}},
 | |
| 			&hst.BadInterfaceError{Interface: "", Segment: "session"}},
 | |
| 		{"dbus system", &hst.Config{SystemBus: &hst.BusConfig{See: []string{""}}},
 | |
| 			&hst.BadInterfaceError{Interface: "", Segment: "system"}},
 | |
| 		{"container", &hst.Config{}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
 | |
| 			Msg: "configuration missing container state"}},
 | |
| 		{"home", &hst.Config{Container: &hst.ContainerConfig{}}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
 | |
| 			Msg: "container configuration missing path to home directory"}},
 | |
| 		{"shell", &hst.Config{Container: &hst.ContainerConfig{
 | |
| 			Home: fhs.AbsTmp,
 | |
| 		}}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
 | |
| 			Msg: "container configuration missing path to shell"}},
 | |
| 		{"path", &hst.Config{Container: &hst.ContainerConfig{
 | |
| 			Home:  fhs.AbsTmp,
 | |
| 			Shell: fhs.AbsTmp,
 | |
| 		}}, &hst.AppError{Step: "validate configuration", Err: hst.ErrConfigNull,
 | |
| 			Msg: "container configuration missing path to initial program"}},
 | |
| 		{"env equals", &hst.Config{Container: &hst.ContainerConfig{
 | |
| 			Home:  fhs.AbsTmp,
 | |
| 			Shell: fhs.AbsTmp,
 | |
| 			Path:  fhs.AbsTmp,
 | |
| 			Env:   map[string]string{"TERM=": ""},
 | |
| 		}}, &hst.AppError{Step: "validate configuration", Err: hst.ErrEnviron,
 | |
| 			Msg: `invalid environment variable "TERM="`}},
 | |
| 		{"env NUL", &hst.Config{Container: &hst.ContainerConfig{
 | |
| 			Home:  fhs.AbsTmp,
 | |
| 			Shell: fhs.AbsTmp,
 | |
| 			Path:  fhs.AbsTmp,
 | |
| 			Env:   map[string]string{"TERM\x00": ""},
 | |
| 		}}, &hst.AppError{Step: "validate configuration", Err: hst.ErrEnviron,
 | |
| 			Msg: `invalid environment variable "TERM\x00"`}},
 | |
| 		{"valid", &hst.Config{Container: &hst.ContainerConfig{
 | |
| 			Home:  fhs.AbsTmp,
 | |
| 			Shell: fhs.AbsTmp,
 | |
| 			Path:  fhs.AbsTmp,
 | |
| 		}}, nil},
 | |
| 	}
 | |
| 	for _, tc := range testCases {
 | |
| 		t.Run(tc.name, func(t *testing.T) {
 | |
| 			t.Parallel()
 | |
| 			if err := tc.config.Validate(); !reflect.DeepEqual(err, tc.wantErr) {
 | |
| 				t.Errorf("Validate: error = %#v, want %#v", err, tc.wantErr)
 | |
| 			}
 | |
| 		})
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestExtraPermConfig(t *testing.T) {
 | |
| 	t.Parallel()
 | |
| 
 | |
| 	testCases := []struct {
 | |
| 		name   string
 | |
| 		config *hst.ExtraPermConfig
 | |
| 		want   string
 | |
| 	}{
 | |
| 		{"nil", nil, "<invalid>"},
 | |
| 		{"nil path", &hst.ExtraPermConfig{Path: nil}, "<invalid>"},
 | |
| 		{"r", &hst.ExtraPermConfig{Path: fhs.AbsRoot, Read: true}, "r--:/"},
 | |
| 		{"r+", &hst.ExtraPermConfig{Ensure: true, Path: fhs.AbsRoot, Read: true}, "r--+:/"},
 | |
| 		{"w", &hst.ExtraPermConfig{Path: hst.AbsPrivateTmp, Write: true}, "-w-:/.hakurei"},
 | |
| 		{"w+", &hst.ExtraPermConfig{Ensure: true, Path: hst.AbsPrivateTmp, Write: true}, "-w-+:/.hakurei"},
 | |
| 		{"x", &hst.ExtraPermConfig{Path: fhs.AbsRunUser, Execute: true}, "--x:/run/user/"},
 | |
| 		{"x+", &hst.ExtraPermConfig{Ensure: true, Path: fhs.AbsRunUser, Execute: true}, "--x+:/run/user/"},
 | |
| 		{"rwx", &hst.ExtraPermConfig{Path: fhs.AbsTmp, Read: true, Write: true, Execute: true}, "rwx:/tmp/"},
 | |
| 		{"rwx+", &hst.ExtraPermConfig{Ensure: true, Path: fhs.AbsTmp, Read: true, Write: true, Execute: true}, "rwx+:/tmp/"},
 | |
| 	}
 | |
| 
 | |
| 	for _, tc := range testCases {
 | |
| 		t.Run(tc.name, func(t *testing.T) {
 | |
| 			t.Parallel()
 | |
| 			if got := tc.config.String(); got != tc.want {
 | |
| 				t.Errorf("String: %q, want %q", got, tc.want)
 | |
| 			}
 | |
| 		})
 | |
| 	}
 | |
| }
 |