diff --git a/api/lql.go b/api/lql.go index 026f52ca4..399159d83 100644 --- a/api/lql.go +++ b/api/lql.go @@ -184,8 +184,8 @@ type LQLService struct { client *Client } -func (svc *LQLService) CreateQuery(query string) ( - response LQLQuery, +func (svc *LQLService) Create(query string) ( + response LQLQueryResponse, err error, ) { lqlQuery := LQLQuery{QueryBlob: query} @@ -197,8 +197,8 @@ func (svc *LQLService) CreateQuery(query string) ( return } -func (svc *LQLService) UpdateQuery(query string) ( - response LQLQuery, +func (svc *LQLService) Update(query string) ( + response LQLQueryResponse, err error, ) { lqlQuery := LQLQuery{QueryBlob: query} @@ -211,10 +211,10 @@ func (svc *LQLService) UpdateQuery(query string) ( } func (svc *LQLService) GetQueries() (LQLQueryResponse, error) { - return svc.GetQueryByID("") + return svc.GetByID("") } -func (svc *LQLService) GetQueryByID(queryID string) ( +func (svc *LQLService) GetByID(queryID string) ( response LQLQueryResponse, err error, ) { @@ -228,7 +228,7 @@ func (svc *LQLService) GetQueryByID(queryID string) ( return } -func (svc *LQLService) RunQuery(query, start, end string) ( +func (svc *LQLService) Run(query, start, end string) ( response map[string]interface{}, err error, ) { diff --git a/api/lql_compile.go b/api/lql_compile.go index 69d8a7d48..56d209fd8 100644 --- a/api/lql_compile.go +++ b/api/lql_compile.go @@ -24,7 +24,7 @@ type LQLCompileResponse struct { Message string `json:"message"` } -func (svc *LQLService) CompileQuery(query string) ( +func (svc *LQLService) Compile(query string) ( response LQLCompileResponse, err error, ) { diff --git a/api/lql_compile_test.go b/api/lql_compile_test.go index a9f6637d4..29a62bf46 100644 --- a/api/lql_compile_test.go +++ b/api/lql_compile_test.go @@ -96,7 +96,7 @@ func TestLQLCompileMethod(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.CompileQuery(lqlQueryStr) + _, err = c.LQL.Compile(lqlQueryStr) assert.Nil(t, err) } @@ -116,7 +116,7 @@ func TestLQLCompileBadInput(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.CompileQuery("") + _, err = c.LQL.Compile("") assert.Equal(t, api.LQLQueryTranslateError, err.Error()) } @@ -142,7 +142,7 @@ func TestLQLCompileOK(t *testing.T) { _ = json.Unmarshal([]byte(mockResponse), &compileExpected) var compileActual api.LQLCompileResponse - compileActual, err = c.LQL.CompileQuery(lqlQueryStr) + compileActual, err = c.LQL.Compile(lqlQueryStr) assert.Nil(t, err) assert.Equal(t, compileExpected, compileActual) } @@ -163,6 +163,6 @@ func TestLQLCompileError(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.CompileQuery(lqlQueryStr) + _, err = c.LQL.Compile(lqlQueryStr) assert.NotNil(t, err) } diff --git a/api/lql_delete.go b/api/lql_delete.go index f413fcb29..f4b865693 100644 --- a/api/lql_delete.go +++ b/api/lql_delete.go @@ -38,7 +38,7 @@ type LQLDeleteMessage struct { ID string `json:"lqlDeleted"` } -func (svc *LQLService) DeleteQuery(queryID string) ( +func (svc *LQLService) Delete(queryID string) ( response LQLDeleteResponse, err error, ) { diff --git a/api/lql_delete_test.go b/api/lql_delete_test.go index 24b73ff2f..92c20163a 100644 --- a/api/lql_delete_test.go +++ b/api/lql_delete_test.go @@ -52,7 +52,7 @@ func TestLQLDeleteMethod(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.DeleteQuery(lqlQueryID) + _, err = c.LQL.Delete(lqlQueryID) assert.Nil(t, err) } @@ -72,15 +72,12 @@ func TestLQLDeleteBadInput(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.DeleteQuery("") + _, err = c.LQL.Delete("") assert.NotNil(t, err) } func TestLQLDeleteOK(t *testing.T) { - mockResponse := mockLQLMessageResponse( - fmt.Sprintf(`"lqlDeleted": "%s"`, lqlQueryID), - "true", - ) + mockResponse := mockLQLMessageResponse(fmt.Sprintf(`"lqlDeleted": "%s"`, lqlQueryID)) fakeServer := lacework.MockServer() fakeServer.MockAPI( @@ -101,7 +98,7 @@ func TestLQLDeleteOK(t *testing.T) { _ = json.Unmarshal([]byte(mockResponse), &deleteExpected) var deleteActual api.LQLDeleteResponse - deleteActual, err = c.LQL.DeleteQuery(lqlQueryID) + deleteActual, err = c.LQL.Delete(lqlQueryID) assert.Nil(t, err) assert.Equal(t, deleteExpected, deleteActual) @@ -123,6 +120,6 @@ func TestLQLDeleteNotFound(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.DeleteQuery(lqlQueryID) + _, err = c.LQL.Delete(lqlQueryID) assert.NotNil(t, err) } diff --git a/api/lql_test.go b/api/lql_test.go index baa96c503..247b0f30a 100644 --- a/api/lql_test.go +++ b/api/lql_test.go @@ -32,12 +32,12 @@ import ( ) var ( - lqlQueryID = "my_lql" - lqlQueryStr = "my_lql { source { CloudTrailRawEvents } return { INSERT_ID } }" - lqlCreateResponse = `{ + lqlQueryID = "my_lql" + lqlQueryStr = "my_lql { source { CloudTrailRawEvents } return { INSERT_ID } }" + lqlCreateData = `[{ "lql_id": "my_lql", "query_text": "my_lql { source { CloudTrailRawEvents } return { INSERT_ID } }" -}` +}]` lqlRunData = `[ { "INSERT_ID": "35308423" @@ -46,8 +46,8 @@ var ( lqlErrorReponse = mockLQLDataResponse( `{ "message": "Error Serving Request" }`, ) - lqlUnableResponse = mockLQLMessageResponse( - `"message": "{\"error\":\"Error: Unable to locate lql query NoSuchQuery, please double check the query exists and has not already been updated.\"}"`, + lqlUnableResponse = mockLQLErrorResponse( + `"{\"error\":\"Error: Unable to locate lql query NoSuchQuery, please double check the query exists and has not already been updated.\"}"`, "false", ) ) @@ -394,9 +394,16 @@ func mockLQLDataResponse(data string) string { }` } -func mockLQLMessageResponse(message string, ok string) string { +func mockLQLErrorResponse(message string, ok string) string { + return `{ + "ok": ` + ok + `, + "data": { "message": {` + message + `} } + }` +} + +func mockLQLMessageResponse(message string) string { return `{ - "ok": ` + ok + `, + "ok": true, "message": {` + message + ` } }` @@ -419,7 +426,7 @@ func TestLQLCreateMethod(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.CreateQuery(lqlQueryStr) + _, err = c.LQL.Create(lqlQueryStr) assert.Nil(t, err) } @@ -439,16 +446,18 @@ func TestLQLCreateBadInput(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.CreateQuery("") + _, err = c.LQL.Create("") assert.Equal(t, api.LQLQueryTranslateError, err.Error()) } func TestLQLCreateOK(t *testing.T) { + mockResponse := mockLQLDataResponse(lqlCreateData) + fakeServer := lacework.MockServer() fakeServer.MockAPI( "external/lql", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, lqlCreateResponse) + fmt.Fprint(w, mockResponse) }, ) defer fakeServer.Close() @@ -459,11 +468,11 @@ func TestLQLCreateOK(t *testing.T) { ) assert.Nil(t, err) - createExpected := api.LQLQuery{} - _ = json.Unmarshal([]byte(lqlCreateResponse), &createExpected) + createExpected := api.LQLQueryResponse{} + _ = json.Unmarshal([]byte(mockResponse), &createExpected) - var createActual api.LQLQuery - createActual, err = c.LQL.CreateQuery(lqlQueryStr) + var createActual api.LQLQueryResponse + createActual, err = c.LQL.Create(lqlQueryStr) assert.Nil(t, err) assert.Equal(t, createExpected, createActual) @@ -485,7 +494,7 @@ func TestLQLCreateError(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.CreateQuery(lqlQueryStr) + _, err = c.LQL.Create(lqlQueryStr) assert.NotNil(t, err) } @@ -517,7 +526,7 @@ func TestLQLGetQueriesMethod(t *testing.T) { } func TestLQLGetQueryByIDOK(t *testing.T) { - mockResponse := mockLQLDataResponse("[" + lqlCreateResponse + "]") + mockResponse := mockLQLDataResponse(lqlCreateData) fakeServer := lacework.MockServer() fakeServer.MockAPI( @@ -534,17 +543,17 @@ func TestLQLGetQueryByIDOK(t *testing.T) { ) assert.Nil(t, err) - createExpected := api.LQLQueryResponse{} - _ = json.Unmarshal([]byte(mockResponse), &createExpected) + getExpected := api.LQLQueryResponse{} + _ = json.Unmarshal([]byte(mockResponse), &getExpected) - var createActual api.LQLQueryResponse - createActual, err = c.LQL.GetQueryByID(lqlQueryStr) + var getActual api.LQLQueryResponse + getActual, err = c.LQL.GetByID(lqlQueryID) assert.Nil(t, err) - assert.Equal(t, createExpected, createActual) + assert.Equal(t, getExpected, getActual) } -func TestLQLGetQueryByIDNotFound(t *testing.T) { +func TestLQLGetByIDNotFound(t *testing.T) { fakeServer := lacework.MockServer() fakeServer.MockAPI( "external/lql", @@ -560,11 +569,11 @@ func TestLQLGetQueryByIDNotFound(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.GetQueryByID("NoSuchQuery") + _, err = c.LQL.GetByID("NoSuchQuery") assert.NotNil(t, err) } -func TestLQLRunQueryMethod(t *testing.T) { +func TestLQLRunMethod(t *testing.T) { fakeServer := lacework.MockServer() fakeServer.MockAPI( "external/lql/query", @@ -581,11 +590,11 @@ func TestLQLRunQueryMethod(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.RunQuery(lqlQueryStr, "0", "1") + _, err = c.LQL.Run(lqlQueryStr, "0", "1") assert.Nil(t, err) } -func TestLQLRunQueryBadInput(t *testing.T) { +func TestLQLRunBadInput(t *testing.T) { fakeServer := lacework.MockServer() fakeServer.MockAPI( "external/lql/query", @@ -601,11 +610,11 @@ func TestLQLRunQueryBadInput(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.RunQuery("", "", "") + _, err = c.LQL.Run("", "", "") assert.Equal(t, api.LQLQueryTranslateError, err.Error()) } -func TestLQLRunQueryOK(t *testing.T) { +func TestLQLRunOK(t *testing.T) { mockResponse := mockLQLDataResponse(lqlRunData) fakeServer := lacework.MockServer() @@ -627,13 +636,13 @@ func TestLQLRunQueryOK(t *testing.T) { _ = json.Unmarshal([]byte(mockResponse), &runExpected) var runActual map[string]interface{} - runActual, err = c.LQL.RunQuery(lqlQueryStr, "0", "1") + runActual, err = c.LQL.Run(lqlQueryStr, "0", "1") assert.Nil(t, err) assert.Equal(t, runExpected, runActual) } -func TestLQLRunQueryError(t *testing.T) { +func TestLQLRunError(t *testing.T) { fakeServer := lacework.MockServer() fakeServer.MockAPI( "external/lql", @@ -649,6 +658,6 @@ func TestLQLRunQueryError(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.CreateQuery(lqlQueryStr) + _, err = c.LQL.Create(lqlQueryStr) assert.NotNil(t, err) } diff --git a/api/lql_update_test.go b/api/lql_update_test.go index 2a258424d..02e2925b7 100644 --- a/api/lql_update_test.go +++ b/api/lql_update_test.go @@ -30,10 +30,10 @@ import ( ) var ( - lqlUpdateResponse = `{ - "lql_id": "my_lql", - "query_text": "my_lql { source { CloudTrailRawEvents } return { INSERT_ID, INSERT_TIME } }" - }` + lqlUpdateData = `[{ + "lql_id": "my_lql", + "query_text": "my_lql { source { CloudTrailRawEvents } return { INSERT_ID, INSERT_TIME } }" +}]` ) func TestLQLUpdateMethod(t *testing.T) { @@ -53,7 +53,7 @@ func TestLQLUpdateMethod(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.UpdateQuery(lqlQueryStr) + _, err = c.LQL.Update(lqlQueryStr) assert.Nil(t, err) } @@ -73,16 +73,18 @@ func TestLQLUpdateBadInput(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.UpdateQuery("") + _, err = c.LQL.Update("") assert.Equal(t, api.LQLQueryTranslateError, err.Error()) } func TestLQLUpdateOK(t *testing.T) { + mockResponse := mockLQLDataResponse(lqlUpdateData) + fakeServer := lacework.MockServer() fakeServer.MockAPI( "external/lql", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, lqlUpdateResponse) + fmt.Fprint(w, mockResponse) }, ) defer fakeServer.Close() @@ -93,11 +95,11 @@ func TestLQLUpdateOK(t *testing.T) { ) assert.Nil(t, err) - updateExpected := api.LQLQuery{} - _ = json.Unmarshal([]byte(lqlUpdateResponse), &updateExpected) + updateExpected := api.LQLQueryResponse{} + _ = json.Unmarshal([]byte(mockResponse), &updateExpected) - var updateActual api.LQLQuery - updateActual, err = c.LQL.UpdateQuery(lqlQueryStr) + var updateActual api.LQLQueryResponse + updateActual, err = c.LQL.Update(lqlQueryStr) assert.Nil(t, err) assert.Equal(t, updateExpected, updateActual) @@ -119,6 +121,6 @@ func TestLQLUpdateNotFound(t *testing.T) { ) assert.Nil(t, err) - _, err = c.LQL.UpdateQuery(lqlQueryStr) + _, err = c.LQL.Update(lqlQueryStr) assert.NotNil(t, err) } diff --git a/cli/cmd/lql.go b/cli/cmd/lql.go index 468fa2776..dd6403cd0 100644 --- a/cli/cmd/lql.go +++ b/cli/cmd/lql.go @@ -184,7 +184,7 @@ func inputQuery(cmd *cobra.Command, args []string) (string, error) { func inputQueryFromEnv(queryID string) (query string, err error) { var queryResponse api.LQLQueryResponse - queryResponse, err = cli.LwApi.LQL.GetQueryByID(queryID) + queryResponse, err = cli.LwApi.LQL.GetByID(queryID) if err == nil && len(queryResponse.Data) != 0 { query = queryResponse.Data[0].QueryText } @@ -308,7 +308,7 @@ func runQuery(cmd *cobra.Command, args []string) error { return compileQueryAndOutput(query) } // !validate_only should should run - response, err := cli.LwApi.LQL.RunQuery(query, lqlCmdState.Start, lqlCmdState.End) + response, err := cli.LwApi.LQL.Run(query, lqlCmdState.Start, lqlCmdState.End) if err != nil { err = queryErrorCrumbs(query, err) diff --git a/cli/cmd/lql_create.go b/cli/cmd/lql_create.go index 860a33daf..13426b0b6 100644 --- a/cli/cmd/lql_create.go +++ b/cli/cmd/lql_create.go @@ -50,15 +50,19 @@ func createQuery(cmd *cobra.Command, args []string) error { } cli.Log.Debugw("creating LQL query", "query", query) - create, err := cli.LwApi.LQL.CreateQuery(query) + create, err := cli.LwApi.LQL.Create(query) if err != nil { err = queryErrorCrumbs(query, err) return errors.Wrap(err, "unable to create LQL query") } if cli.JSONOutput() { - return cli.OutputJSON(create) + return cli.OutputJSON(create.Data) } - cli.OutputHuman(fmt.Sprintf("LQL query (%s) created successfully.\n", create.ID)) + queryID := "unknown" + if len(create.Data) > 0 { + queryID = create.Data[0].ID + } + cli.OutputHuman(fmt.Sprintf("LQL query (%s) created successfully.\n", queryID)) return nil } diff --git a/cli/cmd/lql_delete.go b/cli/cmd/lql_delete.go index e07c24567..14fbe45d1 100644 --- a/cli/cmd/lql_delete.go +++ b/cli/cmd/lql_delete.go @@ -44,7 +44,7 @@ func init() { func deleteQuery(_ *cobra.Command, args []string) error { cli.Log.Debugw("deleting LQL query", "queryID", args[0]) - delete, err := cli.LwApi.LQL.DeleteQuery(args[0]) + delete, err := cli.LwApi.LQL.Delete(args[0]) if err != nil { return errors.Wrap(err, "unable to delete LQL query") @@ -53,6 +53,6 @@ func deleteQuery(_ *cobra.Command, args []string) error { return cli.OutputJSON(delete.Message) } cli.OutputHuman( - fmt.Sprintf("LQL query (%s) deleted successfully.\n", delete.Message.ID)) + fmt.Sprintf("LQL query (%s) deleted successfully.\n", args[0])) return nil } diff --git a/cli/cmd/lql_show.go b/cli/cmd/lql_show.go index 18e27926e..474aff1f8 100644 --- a/cli/cmd/lql_show.go +++ b/cli/cmd/lql_show.go @@ -41,7 +41,7 @@ func init() { func showQuery(_ *cobra.Command, args []string) error { cli.Log.Debugw("retrieving LQL query", "queryID", args[0]) - queryResponse, err := cli.LwApi.LQL.GetQueryByID(args[0]) + queryResponse, err := cli.LwApi.LQL.GetByID(args[0]) if err != nil { return errors.Wrap(err, "unable to show LQL query") diff --git a/cli/cmd/lql_update.go b/cli/cmd/lql_update.go index cce553fe9..f52254702 100644 --- a/cli/cmd/lql_update.go +++ b/cli/cmd/lql_update.go @@ -52,16 +52,19 @@ func updateQuery(cmd *cobra.Command, args []string) error { } cli.Log.Debugw("updating LQL query", "query", query) - update, err := cli.LwApi.LQL.UpdateQuery(query) + update, err := cli.LwApi.LQL.Update(query) if err != nil { err = queryErrorCrumbs(query, err) return errors.Wrap(err, lqlUpdateUnableMsg) } if cli.JSONOutput() { - return cli.OutputJSON(update) + return cli.OutputJSON(update.Data) } - cli.OutputHuman( - fmt.Sprintf("LQL query (%s) updated successfully.\n", update.ID)) + queryID := "unknown" + if len(update.Data) > 0 { + queryID = update.Data[0].ID + } + cli.OutputHuman(fmt.Sprintf("LQL query (%s) updated successfully.\n", queryID)) return nil } diff --git a/cli/cmd/lql_validate.go b/cli/cmd/lql_validate.go index 0fef3d1ef..e6e1f93b8 100644 --- a/cli/cmd/lql_validate.go +++ b/cli/cmd/lql_validate.go @@ -55,7 +55,7 @@ func validateQuery(cmd *cobra.Command, args []string) error { func compileQueryAndOutput(query string) error { cli.Log.Debugw("validating LQL query", "query", query) - compile, err := cli.LwApi.LQL.CompileQuery(query) + compile, err := cli.LwApi.LQL.Compile(query) if err != nil { err = queryErrorCrumbs(query, err) diff --git a/integration/lql_delete_test.go b/integration/lql_delete_test.go index 501d43494..05a1c298c 100644 --- a/integration/lql_delete_test.go +++ b/integration/lql_delete_test.go @@ -42,7 +42,7 @@ func TestQueryDeleteNoInput(t *testing.T) { out, err, exitcode := LaceworkCLIWithTOMLConfig("query", "delete") assert.Empty(t, out.String(), "STDOUT should be empty") - assert.Contains(t, err.String(), "ERROR unable to delete LQL query: Please specify a valid query ID.") + assert.Contains(t, err.String(), "ERROR accepts 1 arg(s), received 0") assert.Equal(t, 1, exitcode, "EXITCODE is not the expected one") } diff --git a/integration/lql_describe_test.go b/integration/lql_describe_test.go index 55e9a79d2..82796ee45 100644 --- a/integration/lql_describe_test.go +++ b/integration/lql_describe_test.go @@ -43,7 +43,7 @@ func TestQueryDescribeNoInput(t *testing.T) { out, err, exitcode := LaceworkCLIWithTOMLConfig("query", "describe") assert.Empty(t, out.String(), "STDOUT should be empty") - assert.Contains(t, err.String(), "ERROR unable to describe LQL data source: Please specify a valid data source.") + assert.Contains(t, err.String(), "ERROR accepts 1 arg(s), received 0") assert.Equal(t, 1, exitcode, "EXITCODE is not the expected one") } diff --git a/integration/lql_list_test.go b/integration/lql_list_test.go index bf992ccdf..94bf1aee4 100644 --- a/integration/lql_list_test.go +++ b/integration/lql_list_test.go @@ -47,12 +47,12 @@ func TestQueryList(t *testing.T) { out, err, exitcode := LaceworkCLIWithTOMLConfig("query", "list") assert.Contains(t, out.String(), "QUERY ID") - assert.Contains(t, out.String(), "MyLQL") + assert.Contains(t, out.String(), "LW_CLI_AWS_CTA_IntegrationTest") assert.Empty(t, err.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") out, err, exitcode = LaceworkCLIWithTOMLConfig("query", "list", "--json") - assert.Contains(t, out.String(), `"MyLQL"`) + assert.Contains(t, out.String(), `"LW_CLI_AWS_CTA_IntegrationTest"`) assert.Empty(t, err.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") } diff --git a/integration/lql_show_test.go b/integration/lql_show_test.go index 548248f40..611b0c6f3 100644 --- a/integration/lql_show_test.go +++ b/integration/lql_show_test.go @@ -42,7 +42,7 @@ func TestQueryShowNoInput(t *testing.T) { out, err, exitcode := LaceworkCLIWithTOMLConfig("query", "show") assert.Empty(t, out.String(), "STDOUT should be empty") - assert.Contains(t, err.String(), "ERROR unable to show LQL query: Please specify a valid query ID.") + assert.Contains(t, err.String(), "ERROR accepts 1 arg(s), received 0") assert.Equal(t, 1, exitcode, "EXITCODE is not the expected one") } diff --git a/integration/lql_test.go b/integration/lql_test.go index a24202335..ed06c9468 100644 --- a/integration/lql_test.go +++ b/integration/lql_test.go @@ -28,10 +28,10 @@ import ( ) const ( - lqlQueryID string = "MyLQL" - lqlQueryText string = "MyLQL { source { CloudTrailRawEvents } return { INSERT_ID } }" - lqlQueryUpdate string = "MyLQL { source { CloudTrailRawEvents } return { INSERT_ID, INSERT_TIME } }" - lqlQueryURL string = "https://raw.githubusercontent.com/lacework/go-sdk/main/integration/test_resources/lql/MyLQL.lql" + lqlQueryID string = "LW_CLI_AWS_CTA_IntegrationTest" + lqlQueryText string = "LW_CLI_AWS_CTA_IntegrationTest { source { CloudTrailRawEvents } return { INSERT_ID } }" + lqlQueryUpdate string = "LW_CLI_AWS_CTA_IntegrationTest { source { CloudTrailRawEvents } return { INSERT_ID, INSERT_TIME } }" + lqlQueryURL string = "https://raw.githubusercontent.com/lacework/go-sdk/main/integration/test_resources/lql/LW_CLI_AWS_CTA_IntegrationTest.lql" ) var ( diff --git a/integration/policy_test.go b/integration/policy_test.go index 55d838015..685405fa8 100644 --- a/integration/policy_test.go +++ b/integration/policy_test.go @@ -28,16 +28,16 @@ import ( const ( policyText string = `{ - "policy_id": "my-policy-1", + "policy_id": "lacework-clitest-1", "title": "My Policy Title", "enabled": false, "alert_enabled": false, - "lql_id": "MyLQL", + "lql_id": "LW_CLI_AWS_CTA_IntegrationTest", "severity": "low", "description": "My Policy Description", "remediation": "Check yourself..." }` - policyURL string = "https://raw.githubusercontent.com/lacework/go-sdk/main/integration/test_resources/policy/my-policy-1.json" + policyURL string = "https://raw.githubusercontent.com/lacework/go-sdk/main/integration/test_resources/policy/lacework-clitest-1.json" ) func TestPolicyHelp(t *testing.T) { @@ -118,27 +118,27 @@ func TestPolicyCreateFile(t *testing.T) { // update-url (output human) out, stderr, exitcode = LaceworkCLIWithTOMLConfig("policy", "update", "-u", policyURL) - assert.Contains(t, out.String(), "Policy (my-policy-1) updated successfully.") + assert.Contains(t, out.String(), "Policy (lacework-clitest-1) updated successfully.") assert.Empty(t, stderr.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") // list enabled-only out, stderr, exitcode = LaceworkCLIWithTOMLConfig("policy", "list", "--enabled") assert.Contains(t, out.String(), "lacework-global-1") - assert.NotContains(t, out.String(), "my-policy-1") + assert.NotContains(t, out.String(), "lacework-clitest-1") assert.Empty(t, stderr.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") // list alert_enabled-only out, stderr, exitcode = LaceworkCLIWithTOMLConfig("policy", "list", "--alert_enabled") assert.Contains(t, out.String(), "lacework-global-1") - assert.NotContains(t, out.String(), "my-policy-1") + assert.NotContains(t, out.String(), "lacework-clitest-1") assert.Empty(t, stderr.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") // delete - out, stderr, exitcode = LaceworkCLIWithTOMLConfig("policy", "delete", "my-policy-1") - assert.Contains(t, out.String(), "Policy (my-policy-1) deleted successfully.") + out, stderr, exitcode = LaceworkCLIWithTOMLConfig("policy", "delete", "lacework-clitest-1") + assert.Contains(t, out.String(), "Policy (lacework-clitest-1) deleted successfully.") assert.Empty(t, stderr.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") } @@ -155,9 +155,9 @@ func TestPolicyCreateURL(t *testing.T) { // create (output human) out, stderr, exitcode := LaceworkCLIWithTOMLConfig("policy", "create", "-u", policyURL) // teardown policy - defer LaceworkCLIWithTOMLConfig("policy", "delete", "my-policy-1") + defer LaceworkCLIWithTOMLConfig("policy", "delete", "lacework-clitest-1") - assert.Contains(t, out.String(), "Policy (my-policy-1) created successfully.") + assert.Contains(t, out.String(), "Policy (lacework-clitest-1) created successfully.") assert.Empty(t, stderr.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") @@ -345,8 +345,8 @@ func TestPolicyDelete(t *testing.T) { // human delete tested by virtue of TestPolicyCreateFile // json - out, err, exitcode := LaceworkCLIWithTOMLConfig("policy", "delete", "my-policy-1", "--json") - assert.Contains(t, out.String(), `"my-policy-1"`) + out, err, exitcode := LaceworkCLIWithTOMLConfig("policy", "delete", "lacework-clitest-1", "--json") + assert.Contains(t, out.String(), `"lacework-clitest-1"`) assert.Empty(t, err.String(), "STDERR should be empty") assert.Equal(t, 0, exitcode, "EXITCODE is not the expected one") }