Skip to content

Commit

Permalink
remove executable check for valid supervisor config
Browse files Browse the repository at this point in the history
  • Loading branch information
BinaryFissionGames committed Jun 7, 2024
1 parent 6ef968e commit efca1bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 48 deletions.
6 changes: 1 addition & 5 deletions cmd/opampsupervisor/supervisor/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,11 @@ func (a Agent) Validate() error {
return errors.New("agent::executable must be specified")
}

f, err := os.Stat(a.Executable)
_, err := os.Stat(a.Executable)
if err != nil {
return fmt.Errorf("could not stat agent::executable path: %w", err)
}

if f.Mode().Perm()&0111 == 0 {
return fmt.Errorf("agent::executable does not have executable bit set")
}

return nil
}

Expand Down
53 changes: 10 additions & 43 deletions cmd/opampsupervisor/supervisor/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestValidate(t *testing.T) {
},
},
Agent: Agent{
Executable: "${executable_path}",
Executable: "${file_path}",
OrphanDetectionInterval: 5 * time.Second,
},
Capabilities: Capabilities{
Expand All @@ -57,7 +57,7 @@ func TestValidate(t *testing.T) {
},
},
Agent: Agent{
Executable: "${executable_path}",
Executable: "${file_path}",
OrphanDetectionInterval: 5 * time.Second,
},
Capabilities: Capabilities{
Expand All @@ -82,7 +82,7 @@ func TestValidate(t *testing.T) {
},
},
Agent: Agent{
Executable: "${executable_path}",
Executable: "${file_path}",
OrphanDetectionInterval: 5 * time.Second,
},
Capabilities: Capabilities{
Expand All @@ -107,7 +107,7 @@ func TestValidate(t *testing.T) {
},
},
Agent: Agent{
Executable: "${executable_path}",
Executable: "${file_path}",
OrphanDetectionInterval: 5 * time.Second,
},
Capabilities: Capabilities{
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestValidate(t *testing.T) {
},
},
Agent: Agent{
Executable: "${executable_path}",
Executable: "${file_path}",
OrphanDetectionInterval: 5 * time.Second,
},
Capabilities: Capabilities{
Expand Down Expand Up @@ -198,31 +198,6 @@ func TestValidate(t *testing.T) {
},
expectedError: "could not stat agent::executable path:",
},
{
name: "agent executable has no exec bits set",
config: Supervisor{
Server: OpAMPServer{
Endpoint: "wss://localhost:9090/opamp",
Headers: http.Header{
"Header1": []string{"HeaderValue"},
},
TLSSetting: configtls.ClientConfig{
Insecure: true,
},
},
Agent: Agent{
Executable: "${non_executable_path}",
OrphanDetectionInterval: 5 * time.Second,
},
Capabilities: Capabilities{
AcceptsRemoteConfig: true,
},
Storage: Storage{
Directory: "/etc/opamp-supervisor/storage",
},
},
expectedError: "agent::executable does not have executable bit set",
},
{
name: "Invalid orphan detection interval",
config: Supervisor{
Expand All @@ -236,7 +211,7 @@ func TestValidate(t *testing.T) {
},
},
Agent: Agent{
Executable: "${executable_path}",
Executable: "${file_path}",
OrphanDetectionInterval: -1,
},
Capabilities: Capabilities{
Expand All @@ -253,25 +228,17 @@ func TestValidate(t *testing.T) {
// create some fake files for validating agent config
tmpDir := t.TempDir()

executablePath := filepath.Join(tmpDir, "agent.exe")
//#nosec G306 -- need to write executable file for test
require.NoError(t, os.WriteFile(executablePath, []byte{}, 0100))

nonExecutablePath := filepath.Join(tmpDir, "file")
require.NoError(t, os.WriteFile(nonExecutablePath, []byte{}, 0600))
filePath := filepath.Join(tmpDir, "file")
require.NoError(t, os.WriteFile(filePath, []byte{}, 0600))

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Fill in path to agent executable
tc.config.Agent.Executable = os.Expand(tc.config.Agent.Executable,
func(s string) string {
switch s {
case "executable_path":
return executablePath
case "non_executable_path":
return nonExecutablePath
if s == "file_path" {
return filePath
}

return ""
})

Expand Down

0 comments on commit efca1bf

Please sign in to comment.