From 29a0a1a1690c791773da39d6c05d34fc4e21647a Mon Sep 17 00:00:00 2001
From: gotbadger
Date: Wed, 20 Sep 2023 11:10:48 +0100
Subject: [PATCH] test: add coverage for api-key
---
.../.snapshots/TestApiKeyFlags-bad-api-key | 4 +++
.../TestApiKeyFlags-bad-api-key-with-stderr | 11 ++++++++
e2e/flags/api_key_test.go | 28 +++++++++++++++++++
3 files changed, 43 insertions(+)
create mode 100644 e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key
create mode 100644 e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key-with-stderr
create mode 100644 e2e/flags/api_key_test.go
diff --git a/e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key b/e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key
new file mode 100644
index 000000000..dc06ec500
--- /dev/null
+++ b/e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key
@@ -0,0 +1,4 @@
+{}
+
+--
+
diff --git a/e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key-with-stderr b/e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key-with-stderr
new file mode 100644
index 000000000..3325480bb
--- /dev/null
+++ b/e2e/flags/.snapshots/TestApiKeyFlags-bad-api-key-with-stderr
@@ -0,0 +1,11 @@
+{}
+
+--
+Loading rules
+Scanning target e2e/flags/testdata/simple
+
└ 100% [===============] (1/1, 1 files/s) [0s]
+Running Detectors
+Generating dataflow
+Evaluating rules
+Failed to send data to Bearer Cloud. API key does not appear to be valid for my.bearer.sh.
+
diff --git a/e2e/flags/api_key_test.go b/e2e/flags/api_key_test.go
new file mode 100644
index 000000000..aecca9b39
--- /dev/null
+++ b/e2e/flags/api_key_test.go
@@ -0,0 +1,28 @@
+package flags_test
+
+import (
+ "path/filepath"
+ "testing"
+
+ "github.com/bearer/bearer/e2e/internal/testhelper"
+)
+
+func TestApiKeyFlags(t *testing.T) {
+ t.Parallel()
+ arguments := []string{
+ "scan",
+ filepath.Join("e2e", "flags", "testdata", "simple"),
+ "--disable-version-check",
+ "--disable-default-rules",
+ "--api-key",
+ "123",
+ "--format",
+ "json",
+ }
+ tests := []testhelper.TestCase{
+ testhelper.NewTestCase("bad-api-key-with-stderr", arguments, testhelper.TestCaseOptions{DisplayStdErr: true, IgnoreForce: true}),
+ testhelper.NewTestCase("bad-api-key", arguments, testhelper.TestCaseOptions{DisplayStdErr: false, IgnoreForce: true}),
+ }
+
+ testhelper.RunTests(t, tests)
+}