Skip to content
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

DXCDT-386: Expand logs test cases #663

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion internal/cli/log_streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ func (c *cli) logStreamPickerOptionsByType(desiredType logStreamType) pickerOpti
}
}
if len(options) == 0 {
return nil, fmt.Errorf("there are currently no log streams of type: %s", desiredType)
return nil, fmt.Errorf(
"there are currently no log streams of type: %q, use 'auth0 logs streams create %s' to create one",
desiredType,
desiredType,
)
Comment on lines +292 to +296
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always give command hints in other places, so this just makes things consistent.

}

return options, nil
Expand Down
10 changes: 10 additions & 0 deletions internal/cli/log_streams_datadog.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func updateLogStreamsDatadogCmd(cli *cli) *cobra.Command {
return fmt.Errorf("failed to read log stream with ID %s: %w", inputs.ID, err)
}

if oldLogStream.GetType() != string(logStreamTypeDatadog) {
return fmt.Errorf(
"the log stream with ID %q is of type %q instead of datadog, "+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use logStreamTypeDatadog here?

"use 'auth0 logs streams update %s' to update it instead",
inputs.ID,
oldLogStream.GetType(),
oldLogStream.GetType(),
)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we prevent a panic down below when we type cast the sink property, this safeguards us against passing a real log stream ID but of different type. This is replicated in all the update commands.

if err := logStreamName.AskU(cmd, &inputs.Name, oldLogStream.Name); err != nil {
return err
}
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/log_streams_event_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func updateLogStreamsAmazonEventBridgeCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "eventbridge",
Args: cobra.NoArgs,
Args: cobra.MaximumNArgs(1),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug where we weren't accepting any log stream id for the update command. We fix this here and in other update commands down below.

Short: "Update an existing Amazon Event Bridge log stream",
Long: "Stream real-time Auth0 data to over 15 targets like AWS Lambda.\n\n" +
"To update interactively, use `auth0 logs streams create eventbridge` with no arguments.\n\n" +
Expand All @@ -124,6 +124,16 @@ func updateLogStreamsAmazonEventBridgeCmd(cli *cli) *cobra.Command {
return fmt.Errorf("failed to read log stream with ID %s: %w", inputs.ID, err)
}

if oldLogStream.GetType() != string(logStreamTypeAmazonEventBridge) {
return fmt.Errorf(
"the log stream with ID %q is of type %q instead of eventbridge, "+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use logStreamTypeAmazonEventBridge here?

"use 'auth0 logs streams update %s' to update it instead",
inputs.ID,
oldLogStream.GetType(),
oldLogStream.GetType(),
)
}

if err := logStreamName.AskU(cmd, &inputs.Name, oldLogStream.Name); err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions internal/cli/log_streams_event_grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ func updateLogStreamsAzureEventGridCmd(cli *cli) *cobra.Command {
return fmt.Errorf("failed to read log stream with ID %s: %w", inputs.ID, err)
}

if oldLogStream.GetType() != string(logStreamTypeAzureEventGrid) {
return fmt.Errorf(
"the log stream with ID %q is of type %q instead of eventgrid, "+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use logStreamTypeAzureEventGrid here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the other log types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 129d72f (#663)

"use 'auth0 logs streams update %s' to update it instead",
inputs.ID,
oldLogStream.GetType(),
oldLogStream.GetType(),
)
}

if err := logStreamName.AskU(cmd, &inputs.Name, oldLogStream.Name); err != nil {
return err
}
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/log_streams_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func updateLogStreamsCustomWebhookCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "http",
Args: cobra.NoArgs,
Args: cobra.MaximumNArgs(1),
Short: "Update an existing Custom Webhook log stream",
Long: "Specify a URL you'd like Auth0 to post events to.\n\n" +
"To update interactively, use `auth0 logs streams create http` with no arguments.\n\n" +
Expand Down Expand Up @@ -173,6 +173,16 @@ func updateLogStreamsCustomWebhookCmd(cli *cli) *cobra.Command {
return fmt.Errorf("failed to read log stream with ID %s: %w", inputs.ID, err)
}

if oldLogStream.GetType() != string(logStreamTypeHTTP) {
return fmt.Errorf(
"the log stream with ID %q is of type %q instead of http, "+
"use 'auth0 logs streams update %s' to update it instead",
inputs.ID,
oldLogStream.GetType(),
oldLogStream.GetType(),
)
}

if err := logStreamName.AskU(cmd, &inputs.Name, oldLogStream.Name); err != nil {
return err
}
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/log_streams_splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func updateLogStreamsSplunkCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "splunk",
Args: cobra.NoArgs,
Args: cobra.MaximumNArgs(1),
Short: "Update an existing Splunk log stream",
Long: "Monitor real-time logs and display log analytics.\n\n" +
"To update interactively, use `auth0 logs streams create splunk` with no arguments.\n\n" +
Expand Down Expand Up @@ -163,6 +163,16 @@ func updateLogStreamsSplunkCmd(cli *cli) *cobra.Command {
return fmt.Errorf("failed to read log stream with ID %s: %w", inputs.ID, err)
}

if oldLogStream.GetType() != string(logStreamTypeSplunk) {
return fmt.Errorf(
"the log stream with ID %q is of type %q instead of splunk, "+
"use 'auth0 logs streams update %s' to update it instead",
inputs.ID,
oldLogStream.GetType(),
oldLogStream.GetType(),
)
}

if err := logStreamName.AskU(cmd, &inputs.Name, oldLogStream.Name); err != nil {
return err
}
Expand Down
12 changes: 11 additions & 1 deletion internal/cli/log_streams_sumo.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func updateLogStreamsSumoLogicCmd(cli *cli) *cobra.Command {

cmd := &cobra.Command{
Use: "sumo",
Args: cobra.NoArgs,
Args: cobra.MaximumNArgs(1),
Short: "Update an existing Sumo Logic log stream",
Long: "Visualize logs and detect threats faster with security insights.\n\n" +
"To update interactively, use `auth0 logs streams create sumo` with no arguments.\n\n" +
Expand Down Expand Up @@ -111,6 +111,16 @@ func updateLogStreamsSumoLogicCmd(cli *cli) *cobra.Command {
return fmt.Errorf("failed to read log stream with ID %s: %w", inputs.ID, err)
}

if oldLogStream.GetType() != string(logStreamTypeSumo) {
return fmt.Errorf(
"the log stream with ID %q is of type %q instead of sumo, "+
"use 'auth0 logs streams update %s' to update it instead",
inputs.ID,
oldLogStream.GetType(),
oldLogStream.GetType(),
)
}

if err := logStreamName.AskU(cmd, &inputs.Name, oldLogStream.Name); err != nil {
return err
}
Expand Down
139 changes: 139 additions & 0 deletions test/integration/logs-test-cases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
config:
inherit-env: true

tests:
001 - it successfully lists all logs:
command: auth0 logs list
exit-code: 0
stdout:
contains:
- TYPE
- DESCRIPTION
- DATE
- CONNECTION
- CLIENT

002 - it successfully lists all log streams:
command: auth0 logs streams list
exit-code: 0

003 - it successfully creates a datadog log stream:
command: ./test/integration/scripts/create-log-stream-datadog-id.sh
exit-code: 0

004 - given a datadog log stream, it successfully gets the log stream's details:
command: auth0 logs streams show $(cat ./test/integration/identifiers/log-stream-datadog-id)
exit-code: 0
stdout:
contains:
- NAME integration-test-datadog
- TYPE datadog
- STATUS active

005 - given a datadog log stream, it successfully gets the log stream's details and outputs in json:
command: auth0 logs streams show $(cat ./test/integration/identifiers/log-stream-datadog-id) --json
exit-code: 0
stdout:
json:
name: "integration-test-datadog"
type: "datadog"
status: "active"
sink.datadogRegion: "eu"

006 - given a datadog log stream, it successfully updates the log stream's details:
command: auth0 logs streams update datadog $(cat ./test/integration/identifiers/log-stream-datadog-id) --name integration-test-updated-datadog --region us --api-key 123123123123123 --json
exit-code: 0
stdout:
json:
name: "integration-test-updated-datadog"
type: "datadog"
status: "active"
sink.datadogRegion: "us"

007 - given a datadog log stream, it successfully opens the log stream's settings page:
command: auth0 logs streams open $(cat ./test/integration/identifiers/log-stream-datadog-id) --no-input
exit-code: 0
stderr:
contains:
- "Open the following URL in a browser"

008 - given a datadog log stream, it successfully deletes the log stream:
command: auth0 logs streams delete $(cat ./test/integration/identifiers/log-stream-datadog-id) --force --no-input
exit-code: 0

009 - it successfully creates an eventbridge log stream:
command: ./test/integration/scripts/create-log-stream-eventbridge-id.sh
exit-code: 0

010 - given an eventbridge log stream, it successfully updates the log stream's details:
command: auth0 logs streams update eventbridge $(cat ./test/integration/identifiers/log-stream-eventbridge-id) --name integration-test-updated-eventbridge --json
exit-code: 0
stdout:
json:
name: "integration-test-updated-eventbridge"
type: "eventbridge"
status: "active"

011 - given an eventbridge log stream, it successfully deletes the log stream:
command: auth0 logs streams delete $(cat ./test/integration/identifiers/log-stream-eventbridge-id) --force --no-input
exit-code: 0

012 - it successfully creates an http log stream:
command: ./test/integration/scripts/create-log-stream-http-id.sh
exit-code: 0

013 - given an http log stream, it successfully updates the log stream's details:
command: auth0 logs streams update http $(cat ./test/integration/identifiers/log-stream-http-id) --name integration-test-updated-http --endpoint "https://example.com/webhook/logs/v2" --format "JSONOBJECT" --json --no-input
exit-code: 0
stdout:
json:
name: "integration-test-updated-http"
type: "http"
status: "active"
sink.httpContentFormat: "JSONOBJECT"
sink.httpContentType: "application/json"
sink.httpEndpoint: "https://example.com/webhook/logs/v2"


014 - given an http log stream, it successfully deletes the log stream:
command: auth0 logs streams delete $(cat ./test/integration/identifiers/log-stream-http-id) --force --no-input
exit-code: 0

015 - it successfully creates a splunk log stream:
command: ./test/integration/scripts/create-log-stream-splunk-id.sh
exit-code: 0

016 - given a splunk log stream, it successfully updates the log stream's details:
command: auth0 logs streams update splunk $(cat ./test/integration/identifiers/log-stream-splunk-id) --name integration-test-updated-splunk --domain "example.splunk.com" --token "92a34ab5-c6d7-8901-23ef-456b7c89d0c1" --port 8000 --secure --json --no-input
exit-code: 0
stdout:
json:
name: "integration-test-updated-splunk"
type: "splunk"
status: "active"
sink.splunkDomain: "example.splunk.com"
sink.splunkToken: "92a34ab5-c6d7-8901-23ef-456b7c89d0c1"
sink.splunkPort: "8000"
sink.splunkSecure: "true"

017 - given a splunk log stream, it successfully deletes the log stream:
command: auth0 logs streams delete $(cat ./test/integration/identifiers/log-stream-splunk-id) --force --no-input
exit-code: 0

018 - it successfully creates a sumo log stream:
command: ./test/integration/scripts/create-log-stream-sumo-id.sh
exit-code: 0

019 - given a sumo log stream, it successfully updates the log stream's details:
command: auth0 logs streams update sumo $(cat ./test/integration/identifiers/log-stream-sumo-id) --name integration-test-updated-sumo --source "example.sumo.com" --json --no-input
exit-code: 0
stdout:
json:
name: "integration-test-updated-sumo"
type: "sumo"
status: "active"
sink.sumoSourceAddress: "example.sumo.com"

020 - given a sumo log stream, it successfully deletes the log stream:
command: auth0 logs streams delete $(cat ./test/integration/identifiers/log-stream-sumo-id) --force --no-input
exit-code: 0
6 changes: 6 additions & 0 deletions test/integration/scripts/create-log-stream-datadog-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

logStream=$( auth0 logs streams create datadog --name integration-test-datadog --region eu --api-key 123233123455 --json --no-input )

mkdir -p ./test/integration/identifiers
echo "$logStream" | jq -r '.["id"]' > ./test/integration/identifiers/log-stream-datadog-id
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

logStream=$( auth0 logs streams create eventbridge --name integration-test-eventbridge --aws-id 999999999999 --aws-region eu-west-1 --json --no-input )

mkdir -p ./test/integration/identifiers
echo "$logStream" | jq -r '.["id"]' > ./test/integration/identifiers/log-stream-eventbridge-id
6 changes: 6 additions & 0 deletions test/integration/scripts/create-log-stream-http-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

logStream=$( auth0 logs streams create http --name integration-test-http --endpoint "https://example.com/webhook/logs" --type "application/json" --format "JSONLINES" --json --no-input )

mkdir -p ./test/integration/identifiers
echo "$logStream" | jq -r '.["id"]' > ./test/integration/identifiers/log-stream-http-id
6 changes: 6 additions & 0 deletions test/integration/scripts/create-log-stream-splunk-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

logStream=$( auth0 logs streams create splunk --name integration-test-splunk --domain "demo.splunk.com" --token "12a34ab5-c6d7-8901-23ef-456b7c89d0c1" --port "8088" --secure --json --no-input )

mkdir -p ./test/integration/identifiers
echo "$logStream" | jq -r '.["id"]' > ./test/integration/identifiers/log-stream-splunk-id
6 changes: 6 additions & 0 deletions test/integration/scripts/create-log-stream-sumo-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#! /bin/bash

logStream=$( auth0 logs streams create sumo --name integration-test-sumo --source "demo.sumo.com" --json --no-input )

mkdir -p ./test/integration/identifiers
echo "$logStream" | jq -r '.["id"]' > ./test/integration/identifiers/log-stream-sumo-id
13 changes: 0 additions & 13 deletions test/integration/test-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ tests:
auth0 apis list:
exit-code: 0

auth0 logs list:
exit-code: 0
stdout:
contains:
- TYPE
- DESCRIPTION
- DATE
- CONNECTION
- CLIENT

auth0 logs streams list:
exit-code: 0

auth0 tenants list:
exit-code: 0

Expand Down