mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-12-06 01:53:42 +01:00
63 lines
2.3 KiB
Go
63 lines
2.3 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/oapi-codegen/nullable"
|
|
"github.com/phishingclub/phishingclub/model"
|
|
"github.com/phishingclub/phishingclub/vo"
|
|
)
|
|
|
|
func TestValidateProgramFilterPages(t *testing.T) {
|
|
if err := model.ValidateProgramFilterPages(false, true, 0); err == nil {
|
|
t.Fatal("evasion without deny page must fail")
|
|
}
|
|
if err := model.ValidateProgramFilterPages(false, false, 1); err == nil {
|
|
t.Fatal("filters without deny page must fail")
|
|
}
|
|
if err := model.ValidateProgramFilterPages(true, true, 2); err != nil {
|
|
t.Fatalf("valid setup rejected: %v", err)
|
|
}
|
|
if err := model.ValidateProgramFilterPages(false, false, 0); err != nil {
|
|
t.Fatalf("nothing set must pass: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestProgramChangedFields(t *testing.T) {
|
|
a := uuid.New()
|
|
b := uuid.New()
|
|
tpl := uuid.New()
|
|
existing := &model.Program{
|
|
Name: nullable.NewNullableWithValue(*vo.NewString64Must("p")),
|
|
SpreadMinutes: nullable.NewNullableWithValue(60),
|
|
TimeZone: nullable.NewNullableWithValue("UTC"),
|
|
RecipientGroupIDs: nullable.NewNullableWithValue([]*uuid.UUID{&a, &b}),
|
|
AllowDenyIDs: nullable.NewNullableWithValue([]*uuid.UUID{}),
|
|
Steps: []*model.ProgramStep{{CampaignTemplateID: nullable.NewNullableWithValue(tpl)}},
|
|
}
|
|
incoming := &model.Program{
|
|
Name: nullable.NewNullableWithValue(*vo.NewString64Must("p")),
|
|
SpreadMinutes: nullable.NewNullableWithValue(120),
|
|
TimeZone: nullable.NewNullableWithValue("UTC"),
|
|
RecipientGroupIDs: nullable.NewNullableWithValue([]*uuid.UUID{&b, &a}),
|
|
AllowDenyIDs: nullable.NewNullableWithValue([]*uuid.UUID{&a}),
|
|
Steps: []*model.ProgramStep{{CampaignTemplateID: nullable.NewNullableWithValue(tpl)}},
|
|
}
|
|
got := ProgramChangedFields(existing, incoming)
|
|
want := map[string]bool{"spreadMinutes": true, "allowDenyIDs": true}
|
|
if len(got) != len(want) {
|
|
t.Fatalf("got %v", got)
|
|
}
|
|
for _, f := range got {
|
|
if !want[f] {
|
|
t.Fatalf("unexpected changed field %q in %v", f, got)
|
|
}
|
|
}
|
|
incoming.Steps = []*model.ProgramStep{{CampaignTemplateID: nullable.NewNullableWithValue(uuid.New())}}
|
|
got = ProgramChangedFields(existing, incoming)
|
|
if got[len(got)-1] != "steps" {
|
|
t.Fatalf("step change must be listed, got %v", got)
|
|
}
|
|
}
|