-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): AWS GovCloud Config integration (#421)
- Loading branch information
1 parent
8c53e8e
commit 68d7087
Showing
6 changed files
with
263 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -34,7 +34,7 @@ import ( | |
func TestIntegrationsNewAwsCfgIntegration(t *testing.T) { | ||
subject := api.NewAwsCfgIntegration("integration_name", | ||
api.AwsIntegrationData{ | ||
Credentials: api.AwsCrossAccountCreds{ | ||
Credentials: &api.AwsCrossAccountCreds{ | ||
RoleArn: "arn:foo:bar", | ||
ExternalID: "0123456789", | ||
}, | ||
|
@@ -43,6 +43,28 @@ func TestIntegrationsNewAwsCfgIntegration(t *testing.T) { | |
assert.Equal(t, api.AwsCfgIntegration.String(), subject.Type) | ||
} | ||
|
||
func TestIntegrationsEmptyAwsCredentials(t *testing.T) { | ||
var awsData api.AwsIntegrationData | ||
credentials := awsData.GetCredentials() | ||
|
||
externalID := credentials.ExternalID | ||
roleArn := credentials.RoleArn | ||
assert.Empty(t, externalID) | ||
assert.Empty(t, roleArn) | ||
} | ||
|
||
func TestIntegrationsEmptyAwsGovCloudCredentials(t *testing.T) { | ||
var awsData api.AwsIntegrationData | ||
credentials := awsData.GetGovCloudCredentials() | ||
accountID := awsData.GetAccountID() | ||
|
||
secretKey := credentials.SecretAccessKey | ||
accessID := credentials.AccessKeyID | ||
assert.Empty(t, accountID) | ||
assert.Empty(t, secretKey) | ||
assert.Empty(t, accessID) | ||
} | ||
|
||
func TestIntegrationsNewAwsCfgIntegrationWithCustomTemplateFile(t *testing.T) { | ||
accountMappingJSON := []byte(`{ | ||
"defaultLaceworkAccountAws": "lw_account_1", | ||
|
@@ -62,7 +84,7 @@ func TestIntegrationsNewAwsCfgIntegrationWithCustomTemplateFile(t *testing.T) { | |
} | ||
}`) | ||
awsData := api.AwsIntegrationData{ | ||
Credentials: api.AwsCrossAccountCreds{ | ||
Credentials: &api.AwsCrossAccountCreds{ | ||
RoleArn: "arn:foo:bar", | ||
ExternalID: "0123456789", | ||
}, | ||
|
@@ -120,15 +142,15 @@ func TestIntegrationsCreateAws(t *testing.T) { | |
data := api.NewAwsIntegration("integration_name", | ||
api.AwsCfgIntegration, | ||
api.AwsIntegrationData{ | ||
Credentials: api.AwsCrossAccountCreds{ | ||
Credentials: &api.AwsCrossAccountCreds{ | ||
RoleArn: "arn:foo:bar", | ||
ExternalID: "0123456789", | ||
}, | ||
}, | ||
) | ||
assert.Equal(t, "integration_name", data.Name, "GCP integration name mismatch") | ||
assert.Equal(t, "AWS_CFG", data.Type, "a new GCP integration should match its type") | ||
assert.Equal(t, 1, data.Enabled, "a new GCP integration should be enabled") | ||
assert.Equal(t, "integration_name", data.Name, "AWS integration name mismatch") | ||
assert.Equal(t, "AWS_CFG", data.Type, "a new AWS integration should match its type") | ||
assert.Equal(t, 1, data.Enabled, "a new AWS integration should be enabled") | ||
|
||
response, err := c.Integrations.CreateAws(data) | ||
assert.Nil(t, err) | ||
|
@@ -144,6 +166,65 @@ func TestIntegrationsCreateAws(t *testing.T) { | |
} | ||
} | ||
|
||
func TestIntegrationsCreateAwsGovCloudConfig(t *testing.T) { | ||
var ( | ||
intgGUID = intgguid.New() | ||
fakeServer = lacework.MockServer() | ||
) | ||
|
||
fakeServer.MockAPI("external/integrations", func(w http.ResponseWriter, r *http.Request) { | ||
assert.Equal(t, "POST", r.Method, "CreateAwsGovCloud should be a POST method") | ||
|
||
if assert.NotNil(t, r.Body) { | ||
body := httpBodySniffer(r) | ||
assert.Contains(t, body, "integration_name", "integration name is missing") | ||
assert.Contains(t, body, "AWS_US_GOV_CFG", "wrong integration type") | ||
assert.Contains(t, body, "0123456789", "wrong account id") | ||
assert.Contains(t, body, "AWS123abcAccessKeyID", "wrong access key id") | ||
assert.Contains(t, body, "AWS123abc123abcSecretAccessKey0000000000", "wrong secret access key") | ||
assert.Contains(t, body, "ENABLED\":1", "integration is not enabled") | ||
} | ||
|
||
fmt.Fprintf(w, awsGovCloudIntegrationJsonResponse(intgGUID)) | ||
}) | ||
defer fakeServer.Close() | ||
|
||
c, err := api.NewClient("test", | ||
api.WithToken("TOKEN"), | ||
api.WithURL(fakeServer.URL()), | ||
) | ||
assert.Nil(t, err) | ||
|
||
data := api.NewAwsIntegration("integration_name", | ||
api.AwsGovCloudCfgIntegration, | ||
api.AwsIntegrationData{ | ||
GovCloudCredentials: &api.AwsGovCloudCreds{ | ||
AccountID: "0123456789", | ||
AccessKeyID: "AWS123abcAccessKeyID", | ||
SecretAccessKey: "AWS123abc123abcSecretAccessKey0000000000", | ||
}, | ||
}, | ||
) | ||
assert.Equal(t, "integration_name", data.Name, "AWS integration name mismatch") | ||
assert.Equal(t, "AWS_US_GOV_CFG", data.Type, "a new AWS GovCloud integration should match its type") | ||
assert.Equal(t, 1, data.Enabled, "a new AWS integration should be enabled") | ||
|
||
response, err := c.Integrations.CreateAws(data) | ||
assert.Nil(t, err) | ||
assert.NotNil(t, response) | ||
assert.True(t, response.Ok) | ||
if assert.Equal(t, 1, len(response.Data)) { | ||
resData := response.Data[0] | ||
assert.Equal(t, intgGUID, resData.IntgGuid) | ||
assert.Equal(t, "integration_name", resData.Name) | ||
assert.True(t, resData.State.Ok) | ||
credentials := resData.Data.GetGovCloudCredentials() | ||
assert.Equal(t, "AWS123abcAccessKeyID", credentials.AccessKeyID) | ||
assert.Equal(t, "AWS123abc123abcSecretAccessKey0000000000", credentials.SecretAccessKey) | ||
assert.Equal(t, "0123456789", resData.Data.GetAccountID()) | ||
} | ||
} | ||
|
||
func TestIntegrationsGetAws(t *testing.T) { | ||
var ( | ||
intgGUID = intgguid.New() | ||
|
@@ -208,15 +289,15 @@ func TestIntegrationsUpdateAws(t *testing.T) { | |
data := api.NewAwsIntegration("integration_name", | ||
api.AwsCloudTrailIntegration, | ||
api.AwsIntegrationData{ | ||
Credentials: api.AwsCrossAccountCreds{ | ||
Credentials: &api.AwsCrossAccountCreds{ | ||
RoleArn: "arn:foo:bar", | ||
ExternalID: "0123456789", | ||
}, | ||
}, | ||
) | ||
assert.Equal(t, "integration_name", data.Name, "GCP integration name mismatch") | ||
assert.Equal(t, "AWS_CT_SQS", data.Type, "a new GCP integration should match its type") | ||
assert.Equal(t, 1, data.Enabled, "a new GCP integration should be enabled") | ||
assert.Equal(t, "integration_name", data.Name, "AWS integration name mismatch") | ||
assert.Equal(t, "AWS_CT_SQS", data.Type, "a new AWS integration should match its type") | ||
assert.Equal(t, 1, data.Enabled, "a new AWS integration should be enabled") | ||
data.IntgGuid = intgGUID | ||
|
||
response, err := c.Integrations.UpdateAws(data) | ||
|
@@ -292,6 +373,16 @@ func awsIntegrationJsonResponse(intgGUID string) string { | |
` | ||
} | ||
|
||
func awsGovCloudIntegrationJsonResponse(intgGUID string) string { | ||
return ` | ||
{ | ||
"data": [` + singleAwsGovCloudCfgIntegration(intgGUID) + `], | ||
"ok": true, | ||
"message": "SUCCESS" | ||
} | ||
` | ||
} | ||
|
||
func awsMultiIntegrationJsonResponse(guids []string) string { | ||
integrations := []string{} | ||
for _, guid := range guids { | ||
|
@@ -331,3 +422,30 @@ func singleAwsIntegration(id string) string { | |
} | ||
` | ||
} | ||
|
||
func singleAwsGovCloudCfgIntegration(id string) string { | ||
return ` | ||
{ | ||
"INTG_GUID": "` + id + `", | ||
"NAME": "integration_name", | ||
"CREATED_OR_UPDATED_TIME": "2020-Mar-10 01:00:00 UTC", | ||
"CREATED_OR_UPDATED_BY": "[email protected]", | ||
"TYPE": "AWS_US_GOV_CFG", | ||
"ENABLED": 1, | ||
"STATE": { | ||
"ok": true, | ||
"lastUpdatedTime": "2020-Mar-10 01:00:00 UTC", | ||
"lastSuccessfulTime": "2020-Mar-10 01:00:00 UTC" | ||
}, | ||
"IS_ORG": 0, | ||
"DATA": { | ||
"ACCESS_KEY_CREDENTIALS": { | ||
"ACCOUNT_ID": "0123456789", | ||
"ACCESS_KEY_ID": "AWS123abcAccessKeyID", | ||
"SECRET_ACCESS_KEY": "AWS123abc123abcSecretAccessKey0000000000" | ||
} | ||
}, | ||
"TYPE_NAME": "AWS Compliance" | ||
} | ||
` | ||
} |
This file contains 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 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.