-
Notifications
You must be signed in to change notification settings - Fork 105
Check allowed dir #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Check allowed dir #1007
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
0eb0b71
add log feature flag
aphralG f008dee
naming
aphralG 16be86e
Merge branch 'v3' into add-log-feature-flag
aphralG 875bb59
check allowed dir
aphralG 82279a5
check allowed dir
aphralG f9e231d
Merge branch 'v3' into check-allowed-dir
aphralG 5e3f0a5
change allowed dir
aphralG b2d192f
fix tests
aphralG d0915b3
fix tests
aphralG c8e1f77
remove nginx-agent from allowed
aphralG 9b5ec19
Merge branch 'v3' into check-allowed-dir
aphralG 223cbed
change stuff
aphralG dd9b13e
change stuff
aphralG 143db27
Merge branch 'v3' into check-allowed-dir
aphralG 8da7504
clean up
aphralG 1ae2833
PR feedback
aphralG 385bb02
Merge branch 'v3' into check-allowed-dir
aphralG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright (c) F5, Inc. | ||
| // | ||
| // This source code is licensed under the Apache License, Version 2.0 license found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
|
|
||
| package config | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestTypes_IsDirectoryAllowed(t *testing.T) { | ||
| config := getAgentConfig() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| fileDir string | ||
| allowedDirs []string | ||
| allowed bool | ||
| }{ | ||
| { | ||
| name: "Test 1: directory allowed", | ||
| allowed: true, | ||
| allowedDirs: []string{ | ||
| AgentDirName, | ||
| "/etc/nginx", | ||
| "/var/log/nginx/", | ||
| }, | ||
| fileDir: "/etc/nginx/nginx.conf", | ||
| }, | ||
| { | ||
| name: "Test 2: directory not allowed", | ||
| allowed: false, | ||
| allowedDirs: []string{ | ||
| AgentDirName, | ||
| "/etc/nginx/", | ||
| "/var/log/nginx/", | ||
| }, | ||
| fileDir: "/etc/nginx-test/nginx-agent.conf", | ||
| }, | ||
| { | ||
| name: "Test 3: directory allowed", | ||
| allowed: true, | ||
| allowedDirs: []string{ | ||
| AgentDirName, | ||
| "/etc/nginx/", | ||
| "/var/log/nginx/", | ||
| }, | ||
| fileDir: "/etc/nginx/conf.d/nginx-agent.conf", | ||
| }, | ||
| { | ||
| name: "Test 4: directory not allowed", | ||
| allowed: false, | ||
| allowedDirs: []string{ | ||
| AgentDirName, | ||
| "/etc/nginx", | ||
| "/var/log/nginx", | ||
| }, | ||
| fileDir: "~/test.conf", | ||
| }, | ||
| { | ||
| name: "Test 5: directory not allowed", | ||
| allowed: false, | ||
| allowedDirs: []string{ | ||
| AgentDirName, | ||
| "/etc/nginx/", | ||
| "/var/log/nginx/", | ||
| }, | ||
| fileDir: "//test.conf", | ||
| }, | ||
| { | ||
| name: "Test 6: directory allowed", | ||
| allowed: true, | ||
| allowedDirs: []string{ | ||
| AgentDirName, | ||
| "/etc/nginx/", | ||
| "/var/log/nginx/", | ||
| "/", | ||
| }, | ||
| fileDir: "/test.conf", | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| config.AllowedDirectories = test.allowedDirs | ||
| result := config.IsDirectoryAllowed(test.fileDir) | ||
| assert.Equal(t, test.allowed, result) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.