From f1b140112ba5817ebc40384ec702f4c7d0d21190 Mon Sep 17 00:00:00 2001 From: Tahmid Efaz Date: Fri, 26 Jul 2024 16:04:06 -0400 Subject: [PATCH] adding tests --- Makefile | 3 ++ docker-compose.yml | 2 +- .../controllers/private/private_suite_test.go | 30 +++++++++++++++++++ internal/common/utils/misc.go | 1 - internal/validator/handler_test.go | 14 +++++++++ 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f30afd6a..6bda5187 100644 --- a/Makefile +++ b/Makefile @@ -113,6 +113,9 @@ sample_upload.xz: sample_rhc_sat_upload: curl -v -F "file=@examples/rhcsat-success.jsonl;type=application/vnd.redhat.playbook-sat.v3+jsonl" -H "x-rh-identity: eyJpZGVudGl0eSI6IHsiYWNjb3VudF9udW1iZXIiOiAiMDAwMDAwMSIsICJ0eXBlIjogIlN5c3RlbSIsICJpbnRlcm5hbCI6IHsib3JnX2lkIjogIjAwMDAwMSJ9fX0=" -H "x-rh-request_id: 380b4a04-7eae-4dff-a0b8-6e1af9186df0" http://localhost:8080/api/ingress/v1/upload +sample_blocked_upload: + curl -v -F "file=@examples/events-success.jsonl;type=application/vnd.redhat.playbook.v1+jsonl" -H "x-rh-identity: eyJpZGVudGl0eSI6IHsiYWNjb3VudF9udW1iZXIiOiAiMDAwMDAwMSIsICJ0eXBlIjogIlN5c3RlbSIsICJpbnRlcm5hbCI6IHsib3JnX2lkIjogIjEzMzcifX19" -H "x-rh-request_id: 380b4a04-7eae-4dff-a0b8-6e1af9186df0" http://localhost:8080/api/ingress/v1/upload + sample: sample_request sample_upload connector_create: diff --git a/docker-compose.yml b/docker-compose.yml index 0a138fa3..f582d039 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -78,7 +78,7 @@ services: - '8080:3000' environment: - INGRESS_STAGEBUCKET=insights-upload-perma - - INGRESS_VALIDTOPICS=playbook,playbook-sat + - INGRESS_VALID_UPLOAD_TYPES=playbook,playbook-sat - OPENSHIFT_BUILD_COMMIT=somestring - INGRESS_MAXSIZE=104857600 - INGRESS_MINIODEV=true diff --git a/internal/api/controllers/private/private_suite_test.go b/internal/api/controllers/private/private_suite_test.go index 0ee3520b..3f691d12 100644 --- a/internal/api/controllers/private/private_suite_test.go +++ b/internal/api/controllers/private/private_suite_test.go @@ -7,6 +7,8 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo/extensions/table" . "github.com/onsi/gomega" + + "playbook-dispatcher/internal/common/utils" ) func TestConfig(t *testing.T) { @@ -55,3 +57,31 @@ var _ = Describe("Validation", func() { ), ) }) + +var _ = Describe("Blocklisted OrgIDs", func() { + DescribeTable("validateFields", + func(orgID string, result bool) { + cfg.Set("blocklist.orgids", "1337,1234") + + isBlocked := utils.IsOrgIdBlocklisted(cfg, orgID) + + Expect(isBlocked).To(Equal(result)) + }, + + Entry( + "unblocked orgid", + "01234", + false, + ), + Entry( + "blocked org_id - 1", + "1337", + true, + ), + Entry( + "blocked org_id - 2", + "1234", + true, + ), + ) +}) diff --git a/internal/common/utils/misc.go b/internal/common/utils/misc.go index 5837f2b3..7b6e9e35 100644 --- a/internal/common/utils/misc.go +++ b/internal/common/utils/misc.go @@ -112,7 +112,6 @@ func LoadSchemas(cfg *viper.Viper, schemaNames []string) (schemas []*jsonschema. func IsOrgIdBlocklisted(cfg *viper.Viper, orgId string) bool { blocklistedOrgIds := strings.Split(cfg.GetString("blocklist.orgids"), ",") - if len(blocklistedOrgIds) > 0 { for _, blockedOrgId := range blocklistedOrgIds { if blockedOrgId == orgId { diff --git a/internal/validator/handler_test.go b/internal/validator/handler_test.go index 46a0f6fe..883cb51f 100644 --- a/internal/validator/handler_test.go +++ b/internal/validator/handler_test.go @@ -56,6 +56,20 @@ var _ = Describe("Handler", func() { }) }) + Describe("Blocklisted OrgIDs", func() { + It("Rejects archives if org_id is blocklisted", func() { + cfg.Set("blocklist.orgids", "1337") + + req := &messageModel.IngressValidationRequest{ + OrgID: "1337", + Size: 1024, + } + + err := instance.validateRequest(req) + Expect(err).To(HaveOccurred()) + }) + }) + Describe("Validation", func() { DescribeTable("Rejects invalid files",