MCPcopy Create free account
hub / github.com/BishopFox/cloudfox / TestDatabasesCommand

Function TestDatabasesCommand

aws/databases_test.go:16–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestDatabasesCommand(t *testing.T) {
17
18 m := DatabasesModule{
19 AWSProfile: "unittesting",
20 AWSRegions: []string{"us-east-1"},
21 Caller: sts.GetCallerIdentityOutput{
22 Arn: aws.String("arn:aws:iam::123456789012:user/Alice"),
23 Account: aws.String("123456789012"),
24 },
25 Goroutines: 3,
26 WrapTable: false,
27 RDSClient: &sdk.MockedRDSClient{},
28 DynamoDBClient: &sdk.MockedAWSDynamoDBClient{},
29 RedshiftClient: &sdk.MockedRedshiftClient{},
30 }
31
32 fs := internal.MockFileSystem(true)
33 defer internal.MockFileSystem(false)
34 tmpDir := ptr.ToString(internal.GetLogDirPath())
35
36 m.PrintDatabases(tmpDir, 2)
37 //resultsFile, err := afero.ReadFile(fs, "table/databases.txt")
38 resultsFilePath := filepath.Join(tmpDir, "cloudfox-output/aws/unittesting-123456789012/table/databases.txt")
39 resultsFile, err := afero.ReadFile(fs, resultsFilePath)
40 if err != nil {
41 t.Fatalf("Cannot read output file at %s: %s", resultsFile, err)
42 }
43
44 expectedResults := []string{
45 "db1.cluster-123456789012.us-west-2.rds.amazonaws.com", // make sure it includes the Aurora clusters
46 "db2.cluster-123456789012.us-west-2.rds.amazonaws.com", // make sure it includes the Aurora clusters
47 "db3.cluster-123456789012.us-west-2.neptune.amazonaws.com", // make sure it includes the Neptune instances
48 "db4.cluster-123456789012.us-west-2.docdb.amazonaws.com", // make sure it includes the DocumentDB instances
49 "db1-instances-1.blah.us-west-2.rds.amazonaws.com", // make sure it includes the RDS instances
50 }
51
52 for _, expected := range expectedResults {
53 if !strings.Contains(string(resultsFile), expected) {
54 t.Errorf("Expected %s to be in the results file", expected)
55 }
56 }
57
58}

Callers

nothing calls this directly

Calls 3

PrintDatabasesMethod · 0.95
MockFileSystemFunction · 0.92
GetLogDirPathFunction · 0.92

Tested by

no test coverage detected