-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Asset Inventory][Azure] Add Acitive Directory fetcher to fetch Servi…
- Loading branch information
1 parent
93ee9c2
commit 1dc81c7
Showing
12 changed files
with
707 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package assetinventory | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/elastic/beats/v7/x-pack/libbeat/common/aws" | ||
"github.com/elastic/elastic-agent-libs/logp" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/elastic/cloudbeat/internal/config" | ||
"github.com/elastic/cloudbeat/internal/inventory" | ||
) | ||
|
||
func TestStrategyPicks(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
cfg *config.Config | ||
expectedErr string | ||
}{ | ||
{ | ||
"expected error: asset_inventory_provider not set", | ||
&config.Config{}, | ||
"missing config.v1.asset_inventory_provider", | ||
}, | ||
{ | ||
"expected error: unsupported provider", | ||
&config.Config{ | ||
AssetInventoryProvider: "NOPE", | ||
}, | ||
"unsupported Asset Inventory provider \"NOPE\"", | ||
}, | ||
{ | ||
"expected success: Azure", | ||
&config.Config{ | ||
AssetInventoryProvider: config.ProviderAzure, | ||
}, | ||
"", | ||
}, | ||
{ | ||
"expected error: GCP missing account type", | ||
&config.Config{ | ||
AssetInventoryProvider: config.ProviderGCP, | ||
}, | ||
"invalid gcp account type", | ||
}, | ||
{ | ||
"expected success: GCP", | ||
&config.Config{ | ||
AssetInventoryProvider: config.ProviderGCP, | ||
CloudConfig: config.CloudConfig{ | ||
Gcp: config.GcpConfig{ | ||
AccountType: config.SingleAccount, | ||
ProjectId: "nonexistent", | ||
OrganizationId: "nonexistent", | ||
GcpClientOpt: config.GcpClientOpt{ | ||
CredentialsJSON: "{\"type\": \"service_account\"}", | ||
}, | ||
}, | ||
}, | ||
}, | ||
"could not parse key", | ||
}, | ||
{ | ||
"expected error: AWS unsupported account type", | ||
&config.Config{ | ||
AssetInventoryProvider: config.ProviderAWS, | ||
CloudConfig: config.CloudConfig{ | ||
Aws: config.AwsConfig{ | ||
AccountType: "NOPE", | ||
}, | ||
}, | ||
}, | ||
"unsupported account_type: \"NOPE\"", | ||
}, | ||
{ | ||
"expected success: AWS", | ||
&config.Config{ | ||
AssetInventoryProvider: config.ProviderAWS, | ||
CloudConfig: config.CloudConfig{ | ||
Aws: config.AwsConfig{ | ||
AccountType: config.SingleAccount, | ||
Cred: aws.ConfigAWS{ | ||
AccessKeyID: "key", | ||
SecretAccessKey: "key", | ||
}, | ||
}, | ||
}, | ||
}, | ||
"STS: GetCallerIdentity", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
s := strategy{ | ||
logger: logp.NewLogger("strategy_test"), | ||
cfg: tc.cfg, | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond) | ||
defer cancel() | ||
obj, err := s.NewAssetInventory(ctx, nil) | ||
if tc.expectedErr != "" { | ||
assert.Equal(t, inventory.AssetInventory{}, obj) | ||
require.Error(t, err) | ||
require.ErrorContains(t, err, tc.expectedErr) | ||
} else { | ||
require.NoError(t, err) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.