Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tahmidefaz committed Jul 26, 2024
1 parent 89c67fd commit f1b1401
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions internal/api/controllers/private/private_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
),
)
})
1 change: 0 additions & 1 deletion internal/common/utils/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions internal/validator/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f1b1401

Please sign in to comment.