Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions cmd/cencli/e2e/fixtures/credits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package fixtures

import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/censys/cencli/cmd/cencli/e2e/fixtures/golden"
"github.com/censys/cencli/internal/app/credits"
)

var creditsFixtures = []Fixture{
{
Name: "help",
Args: []string{"--help"},
ExitCode: 0,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertGoldenFile(t, golden.CreditsHelpStdout, stdout, 0)
},
},
{
Name: "basic",
Args: []string{"--output-format", "json"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
data := unmarshalJSONAny[credits.UserCreditDetails](t, stdout)
assert.Greater(t, data.Balance, int64(0))
assert.NotNil(t, data.ResetsAt)
},
},
}
2 changes: 2 additions & 0 deletions cmd/cencli/e2e/fixtures/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ func Fixtures() map[string][]Fixture {
"search": searchFixtures,
"censeye": censeyeFixtures,
"history": historyFixtures,
"credits": creditsFixtures,
"org": orgFixtures,
}
}
22 changes: 22 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/credits_help.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Display credit details for your Free user Censys account.

Note: This command only shows free user credits. If you want to see organization credits,
run "censys org credits" instead.

Usage:
censys credits [flags]

Examples:
censys credits # Show free user credits

Flags:
-h, --help help for credits

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

10 changes: 10 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,14 @@ var (
HistoryHelpStdout []byte
//go:embed root.out
RootStdout []byte
//go:embed credits_help.out
CreditsHelpStdout []byte
//go:embed org_details_help.out
OrgDetailsHelpStdout []byte
//go:embed org_members_help.out
OrgMembersHelpStdout []byte
//go:embed org_credits_help.out
OrgCreditsHelpStdout []byte
//go:embed org_help.out
OrgHelpStdout []byte
)
27 changes: 27 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/org_credits_help.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Display credit details for your organization.

This command shows your organization's credit balance, auto-replenish configuration,
and any credit expirations.

By default, the stored organization ID is used. Use --org-id to query a specific
organization.

Usage:
censys org credits [flags]

Examples:
censys org credits # Show credits for your stored organization
censys org credits --org-id <uuid> # Show credits for a specific organization

Flags:
-h, --help help for credits
-o, --org-id string override the configured organization ID

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

28 changes: 28 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/org_details_help.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Display details about your organization.

This command shows organization information including name, ID, creation date,
and member counts.

By default, the stored organization ID is used. Use --org-id to query a specific
organization.

Usage:
censys org details [flags]

Examples:
censys org details # Show details for your stored organization
censys org details --org-id <uuid> # Show details for a specific organization
censys org details --output-format json # Output as JSON

Flags:
-h, --help help for details
-o, --org-id string override the configured organization ID

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

29 changes: 29 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/org_help.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Manage and view organization details including credits, members, and organization
information.

By default, these commands use your stored organization ID. If no organization ID is
stored,
or you want to query a different organization, use the --org-id flag on each subcommand.

To set your default organization ID, run: censys config org-id set <org-id>

Usage:
censys org [flags]
censys org [command]

Available Commands:
credits Display credit details for your organization
details Display organization details
members List organization members

Flags:
-h, --help help for org

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

30 changes: 30 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/org_members_help.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
List members in your organization.

This command displays all members including their email, name, roles, and last login time.

By default, the stored organization ID is used. Use --org-id to query a specific
organization.
Use --interactive for a navigable table view.

Usage:
censys org members [flags]

Examples:
censys org members # List members for your stored organization
censys org members --interactive # List members in an interactive table
censys org members --org-id <uuid> # List members for a specific organization
censys org members --output-format json # Output as JSON

Flags:
-h, --help help for members
-i, --interactive display results in an interactive table (TUI)
-o, --org-id string override the configured organization ID

Global Flags:
--debug enable debug logging
--no-color disable ANSI colors and styles
--no-spinner disable spinner during operations
-O, --output-format string output format (json|yaml|ndjson|tree|short|template) (default "short")
-q, --quiet suppress non-essential output
--timeout-http duration per-request timeout for HTTP requests (e.g. 10s, 1m) - use 0 to disable

2 changes: 2 additions & 0 deletions cmd/cencli/e2e/fixtures/golden/root.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Available Commands:
censeye Analyze a host and generate pivotable queries with rarity bounds
completion Generate shell completion scripts
config Manage configuration
credits Display credit details for your Censys account
history Retrieve historical data for hosts, web properties, and certificates
org Manage and view organization details
search Execute a search query across Censys data
version Print version information
view Retrieve information about hosts, certificates, and web properties
Expand Down
118 changes: 118 additions & 0 deletions cmd/cencli/e2e/fixtures/org.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package fixtures

import (
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/censys/cencli/cmd/cencli/e2e/fixtures/golden"
"github.com/censys/cencli/internal/app/credits"
"github.com/censys/cencli/internal/app/organizations"
)

var orgFixtures = []Fixture{
{
Name: "help",
Args: []string{"--help"},
ExitCode: 0,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertGoldenFile(t, golden.OrgHelpStdout, stdout, 0)
},
},
{
Name: "help with no args",
Args: []string{},
ExitCode: 0,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertGoldenFile(t, golden.OrgHelpStdout, stdout, 0)
},
},
// ========== credits subcommand ==========
{
Name: "credits help",
Args: []string{"credits", "--help"},
ExitCode: 0,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertGoldenFile(t, golden.OrgCreditsHelpStdout, stdout, 0)
},
},
{
Name: "credits basic",
Args: []string{"credits", "--output-format", "json"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
data := unmarshalJSONAny[credits.OrganizationCreditDetails](t, stdout)
assert.Greater(t, data.Balance, int64(0))
assert.NotNil(t, data.AutoReplenishConfig)
assert.NotNil(t, data.CreditExpirations)
assert.Greater(t, len(data.CreditExpirations), 0)
for _, creditExpiration := range data.CreditExpirations {
assert.Greater(t, creditExpiration.Balance, int64(0))
assert.NotNil(t, creditExpiration.CreationDate)
assert.NotNil(t, creditExpiration.ExpirationDate)
}
},
},
// ========== members subcommand ==========
{
Name: "members help",
Args: []string{"members", "--help"},
ExitCode: 0,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertGoldenFile(t, golden.OrgMembersHelpStdout, stdout, 0)
},
},
{
Name: "members basic",
Args: []string{"members", "--output-format", "json"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
data := unmarshalJSONAny[organizations.OrganizationMembers](t, stdout)
assert.Greater(t, len(data.Members), 0)
for _, member := range data.Members {
assert.NotEmpty(t, member.Email)
assert.NotEmpty(t, member.Roles)
}
},
},
// ========== details subcommand ==========
{
Name: "details help",
Args: []string{"details", "--help"},
ExitCode: 0,
Timeout: 1 * time.Second,
NeedsAuth: false,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertGoldenFile(t, golden.OrgDetailsHelpStdout, stdout, 0)
},
},
{
Name: "details basic",
Args: []string{"details", "--output-format", "json"},
ExitCode: 0,
Timeout: 5 * time.Second,
NeedsAuth: true,
Assert: func(t *testing.T, stdout, stderr []byte) {
assertHas200(t, stderr)
data := unmarshalJSONAny[organizations.OrganizationDetails](t, stdout)
assert.NotEmpty(t, data.Name)
assert.NotEmpty(t, data.CreatedAt)
assert.NotEmpty(t, data.MemberCounts)
},
},
}
Loading