Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/extensions/nginx-app-protect/nap/nap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var (
requiredNAPFiles = []string{BD_SOCKET_PLUGIN_PATH, NAP_VERSION_FILE}
requireNAPProcesses = []string{BD_SOCKET_PLUGIN_PROCESS}
processCheckFunc = core.CheckForProcesses
)

// NewNginxAppProtect returns the object NginxAppProtect, which contains information related
Expand Down Expand Up @@ -158,7 +159,7 @@ func napInstalled(requiredFiles []string) (bool, error) {
// the bool will be false and the error will not be nil.
func napRunning() (bool, error) {
// Check if NAP is running
missingProcesses, err := core.CheckForProcesses(requireNAPProcesses)
missingProcesses, err := processCheckFunc(requireNAPProcesses)
if err != nil {
return false, err
}
Expand Down
9 changes: 7 additions & 2 deletions src/extensions/nginx-app-protect/nap/nap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,13 @@ func TestNAPStatus(t *testing.T) {

// Create fake process(es)
if tc.procsToCreate != nil {
killFakeProcesses := testutils.StartFakeProcesses(tc.procsToCreate, "5")
t.Cleanup(killFakeProcesses)
processCheckFunc = func(processesToCheck []string) ([]string, error) {
return []string{}, nil
}
} else {
processCheckFunc = func(processesToCheck []string) ([]string, error) {
return []string{"fakeProc"}, nil
}
}

// Get running status
Expand Down
12 changes: 4 additions & 8 deletions src/plugins/commander_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,11 @@ func TestCommander_Process(t *testing.T) {
DirectoryMap: &proto.DirectoryMap{},
},
msgTopics: []string{
core.AgentConnected,
core.AgentConnected,
core.AgentConfigChanged,
core.NginxConfigUpload,
core.EnableExtension,
core.EnableExtension,
core.NginxConfigUpload,
core.EnableExtension,
core.EnableExtension,
},
},
{
Expand Down Expand Up @@ -223,7 +219,7 @@ func TestCommander_Process(t *testing.T) {

ctx := context.TODO()
cmdr := tutils.NewMockCommandClient()
mockChannel := testChannel(test.cmd)
mockChannel := testChannel(&proto.Command{})

// setup expectations
cmdr.On("Recv").Return(mockChannel)
Expand All @@ -237,11 +233,11 @@ func TestCommander_Process(t *testing.T) {
messagePipe.Process(core.NewMessage(test.topic, test.cmd))
messagePipe.Run()

processedMessages := messagePipe.GetProcessedMessages()

assert.Eventually(t, func() bool { return len(processedMessages) == len(test.msgTopics) }, 1*time.Second, 100*time.Millisecond)
assert.Eventually(t, func() bool { return len(messagePipe.GetProcessedMessages()) == len(test.msgTopics) }, 1*time.Second, 100*time.Millisecond)
cmdr.AssertExpectations(tt)

processedMessages := messagePipe.GetProcessedMessages()

for idx, msg := range processedMessages {
if test.msgTopics[idx] != msg.Topic() {
tt.Errorf("unexpected message topic: %s :: should have been: %s", msg.Topic(), test.msgTopics[idx])
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.