Skip to content

Commit acad3c3

Browse files
change client IP headers to use colons
1 parent 203abd2 commit acad3c3

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

pkg/commands/ngwaf/workspaces/create.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
4949

5050
// Optional.
5151
c.CmdClause.Flag("attackThresholds", "Attack threshold parameters for system site alerts. Each threshold value is the number of attack signals per IP address that must be detected during the interval before the related IP address is flagged. Input accepted as colon separated string: Immediate:OneMinute:TenMinutes:OneHour").Action(c.attackThresholds.Set).StringVar(&c.attackThresholds.Value)
52-
c.CmdClause.Flag("clientIPHeaders", "Specify the request header containing the client IP address. Input accepted as comma separated string.").Action(c.clientIPHeaders.Set).StringVar(&c.clientIPHeaders.Value)
52+
c.CmdClause.Flag("clientIPHeaders", "Specify the request header containing the client IP address. Input accepted as colon separated string.").Action(c.clientIPHeaders.Set).StringVar(&c.clientIPHeaders.Value)
5353
c.CmdClause.Flag("defaultBlockingCode", "Default status code that is returned when a request to your web application is blocked.").Action(c.defaultBlockingCode.Set).IntVar(&c.defaultBlockingCode.Value)
5454
c.CmdClause.Flag("defaultRedirectURL", "Redirect url to be used if code 301 or 302 is used.").Action(c.defaultRedirectURL.Set).StringVar(&c.defaultRedirectURL.Value)
5555
c.CmdClause.Flag("ipAnonimization", "Agents will anonymize IP addresses according to the option selected.").Action(c.ipAnonimization.Set).StringVar(&c.ipAnonimization.Value)
@@ -73,7 +73,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
7373
}
7474
}
7575
if c.clientIPHeaders.WasSet {
76-
input.ClientIPHeaders = strings.Split(c.clientIPHeaders.Value, ",")
76+
input.ClientIPHeaders = strings.Split(c.clientIPHeaders.Value, ":")
7777
}
7878
if c.defaultBlockingCode.WasSet {
7979
input.DefaultBlockingResponseCode = &c.defaultBlockingCode.Value
@@ -105,6 +105,9 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
105105

106106
func parseAttackSignalThresholds(thresholds string) (*workspaces.AttackSignalThresholdsCreateInput, error) {
107107
thresholdsArray := strings.Split(thresholds, ":")
108+
if len(thresholdsArray) != 4 {
109+
return nil, errors.New("wrong number of inputs for Attack Signal Thresholds")
110+
}
108111
immediate, err := strconv.ParseBool(thresholdsArray[0])
109112
if err != nil {
110113
return nil, err

pkg/commands/ngwaf/workspaces/workspaces_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import (
1616
)
1717

1818
const (
19-
workspaceDescription = "NGWAFCLIWorkspace"
20-
workspaceID = "someID"
21-
workspaceMode = "log"
22-
workspaceName = "CLIWorkspace"
19+
workspaceDescription = "NGWAFCLIWorkspace"
20+
workspaceClientIPHeaders = "these:are:headers"
21+
workspaceID = "someID"
22+
workspaceMode = "log"
23+
workspaceName = "CLIWorkspace"
2324
)
2425

2526
var workspace = workspaces.Workspace{
@@ -29,11 +30,12 @@ var workspace = workspaces.Workspace{
2930
TenMinutes: 0,
3031
OneHour: 0,
3132
},
32-
CreatedAt: testutil.Date,
33-
Description: workspaceDescription,
34-
Mode: workspaceMode,
35-
Name: workspaceName,
36-
WorkspaceID: workspaceID,
33+
ClientIPHeaders: []string{"these", "are", "headers"},
34+
CreatedAt: testutil.Date,
35+
Description: workspaceDescription,
36+
Mode: workspaceMode,
37+
Name: workspaceName,
38+
WorkspaceID: workspaceID,
3739
}
3840

3941
func TestWorkspacesCreate(t *testing.T) {
@@ -68,7 +70,7 @@ func TestWorkspacesCreate(t *testing.T) {
6870
},
6971
{
7072
Name: "validate API success",
71-
Args: fmt.Sprintf("--description %s --name %s --blockingMode %s", workspaceDescription, workspaceName, workspaceMode),
73+
Args: fmt.Sprintf("--description %s --name %s --blockingMode %s --clientIPHeaders %s", workspaceDescription, workspaceName, workspaceMode, workspaceClientIPHeaders),
7274
Client: &http.Client{
7375
Transport: &testutil.MockRoundTripper{
7476
Response: &http.Response{
@@ -82,7 +84,7 @@ func TestWorkspacesCreate(t *testing.T) {
8284
},
8385
{
8486
Name: "validate optional --json flag",
85-
Args: fmt.Sprintf("--description %s --name %s --blockingMode %s --json", workspaceDescription, workspaceName, workspaceMode),
87+
Args: fmt.Sprintf("--description %s --name %s --blockingMode %s --clientIPHeaders %s --json", workspaceDescription, workspaceName, workspaceMode, workspaceClientIPHeaders),
8688
Client: &http.Client{
8789
Transport: &testutil.MockRoundTripper{
8890
Response: &http.Response{

0 commit comments

Comments
 (0)