From 857596e536fbf71987f380eb16029cd725e957ca Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 14 Oct 2022 18:26:38 +0300 Subject: [PATCH] Add flags to sqs and s3 integration tests for key and secret --- .../fltr_update_e1_mongo/cgrates.json | 5 ----- data/conf/samples/ees_s3&sqs/cgrates.json | 12 +++++------ ees/s3_it_test.go | 18 ++++++++++++---- ees/sqs_it_test.go | 21 +++++++++++++++---- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/data/conf/samples/cache_replicate/fltr_update_e1_mongo/cgrates.json b/data/conf/samples/cache_replicate/fltr_update_e1_mongo/cgrates.json index 601d68799..731f4e3f5 100644 --- a/data/conf/samples/cache_replicate/fltr_update_e1_mongo/cgrates.json +++ b/data/conf/samples/cache_replicate/fltr_update_e1_mongo/cgrates.json @@ -5,29 +5,24 @@ "log_level": 7 }, - "listen": { "rpc_json": ":22012", "rpc_gob": ":22013", "http": ":22080" }, - "data_db": { "db_type": "mongo", "db_name": "10", "db_port": 27017 }, - "stor_db": { "db_type": "mongo", "db_name": "cgrates", "db_port": 27017 }, - - "rpc_conns": { "cache_conn": { "strategy": "*broadcast_sync", diff --git a/data/conf/samples/ees_s3&sqs/cgrates.json b/data/conf/samples/ees_s3&sqs/cgrates.json index 0c877abb3..8ad3c900c 100644 --- a/data/conf/samples/ees_s3&sqs/cgrates.json +++ b/data/conf/samples/ees_s3&sqs/cgrates.json @@ -21,11 +21,11 @@ { "id": "sqs_test_file", "type": "*sqs_json_map", - "export_path": "https://sqs.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=AKIAYPZSIYZCZ5U45KEO&awsSecret=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", + "export_path": "https://sqs.eu-central-1.amazonaws.com/", "opts": { "awsRegion": "eu-central-1", - "awsKey": "AKIAYPZSIYZCZ5U45KEO", - "awsSecret": "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", + "awsKey": "set-using-flags", + "awsSecret": "set-using-flags", "sqsQueueID": "testQueue" }, "attempts": 1, @@ -38,11 +38,11 @@ { "id": "s3_test_file", "type": "*s3_json_map", - "export_path": "https://s3.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=AKIAYPZSIYZCZ5U45KEO&awsSecret=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", + "export_path": "https://s3.eu-central-1.amazonaws.com/", "opts": { "awsRegion": "eu-central-1", - "awsKey": "AKIAYPZSIYZCZ5U45KEO", - "awsSecret": "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", + "awsKey": "set-using-flags", + "awsSecret": "set-using-flags", "s3BucketID": "cgrates-cdrs" }, "attempts": 1, diff --git a/ees/s3_it_test.go b/ees/s3_it_test.go index 8eaebae79..044c3c4d0 100644 --- a/ees/s3_it_test.go +++ b/ees/s3_it_test.go @@ -22,6 +22,7 @@ along with this program. If not, see package ees import ( + "fmt" "net/rpc" "path" "testing" @@ -56,6 +57,10 @@ var ( ) func TestS3Export(t *testing.T) { + if awsKey == nil || *awsKey == utils.EmptyString || + awsSecret == nil || *awsSecret == utils.EmptyString { + t.SkipNow() + } s3ConfDir = "ees_s3&sqs" for _, stest := range sTestsS3 { t.Run(s3ConfDir, stest) @@ -68,6 +73,13 @@ func testS3LoadConfig(t *testing.T) { if s3Cfg, err = config.NewCGRConfigFromPath(s3CfgPath); err != nil { t.Error(err) } + for _, value := range s3Cfg.EEsCfg().Exporters { + if value.ID == "sqs_test_file" { + value.ExportPath = fmt.Sprintf("https://s3.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret) + value.Opts.AWSKey = awsKey + value.Opts.AWSSecret = awsSecret + } + } } func testS3ResetDataDB(t *testing.T) { @@ -131,10 +143,8 @@ func testS3ExportEvent(t *testing.T) { } func testS3VerifyExport(t *testing.T) { - endpoint := "https://s3.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=AKIAYPZSIYZCZ5U45KEO&awsSecret=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" + endpoint := fmt.Sprintf("https://s3.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret) region := "eu-central-1" - awsKey := "AKIAYPZSIYZCZ5U45KEO" - awsSecret := "RIUlDyxh7qpoxSBomGOjymIZqSs/pgdXkW16HlKxt" qname := "cgrates-cdrs" key := "key" @@ -143,7 +153,7 @@ func testS3VerifyExport(t *testing.T) { cfg := aws.Config{Endpoint: aws.String(endpoint)} cfg.Region = aws.String(region) - cfg.Credentials = credentials.NewStaticCredentials(awsKey, awsSecret, "") + cfg.Credentials = credentials.NewStaticCredentials(*awsKey, *awsSecret, "") var err error sess, err = session.NewSessionWithOptions( session.Options{ diff --git a/ees/sqs_it_test.go b/ees/sqs_it_test.go index 15e7365ed..98c87693d 100644 --- a/ees/sqs_it_test.go +++ b/ees/sqs_it_test.go @@ -22,6 +22,8 @@ along with this program. If not, see package ees import ( + "flag" + "fmt" "net/rpc" "path" "testing" @@ -38,6 +40,8 @@ import ( ) var ( + awsKey = flag.String("awsKey", utils.EmptyString, "Access key ID for IAM user") + awsSecret = flag.String("awsSecret", utils.EmptyString, "Secret access key") sqsConfDir string sqsCfgPath string sqsCfg *config.CGRConfig @@ -56,6 +60,10 @@ var ( ) func TestSQSExport(t *testing.T) { + if awsKey == nil || *awsKey == utils.EmptyString || + awsSecret == nil || *awsSecret == utils.EmptyString { + t.SkipNow() + } sqsConfDir = "ees_s3&sqs" for _, stest := range sTestsSQS { t.Run(sqsConfDir, stest) @@ -68,6 +76,13 @@ func testSQSLoadConfig(t *testing.T) { if sqsCfg, err = config.NewCGRConfigFromPath(sqsCfgPath); err != nil { t.Error(err) } + for _, value := range sqsCfg.EEsCfg().Exporters { + if value.ID == "sqs_test_file" { + value.ExportPath = fmt.Sprintf("https://sqs.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret) + value.Opts.AWSKey = awsKey + value.Opts.AWSSecret = awsSecret + } + } } func testSQSResetDataDB(t *testing.T) { @@ -132,17 +147,15 @@ func testSQSExportEvent(t *testing.T) { } func testSQSVerifyExport(t *testing.T) { - endpoint := "https://sqs.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=AKIAYPZSIYZCZ5U45KEO&awsSecret=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" + endpoint := fmt.Sprintf("https://sqs.eu-central-1.amazonaws.com/?awsRegion=eu-central-1&awsKey=%s&awsSecret=%s", *awsKey, *awsSecret) region := "eu-central-1" - awsKey := "AKIAYPZSIYZCZ5U45KEO" - awsSecret := "RIUlDyxh7qpoxSBomGOjymIZqSs/pgdXkW16HlKxt" qname := "testQueue" var sess *session.Session cfg := aws.Config{Endpoint: aws.String(endpoint)} cfg.Region = aws.String(region) var err error - cfg.Credentials = credentials.NewStaticCredentials(awsKey, awsSecret, "") + cfg.Credentials = credentials.NewStaticCredentials(*awsKey, *awsSecret, "") sess, err = session.NewSessionWithOptions( session.Options{ Config: cfg,