From b62a3383bf09645fcae4ed210cacfa1c7b9ad84d Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Fri, 4 Sep 2026 11:01:25 +0600 Subject: [PATCH] Treat bitcoin/coinbase mentions as spam in KubeDB Inquiry Reject KubeDB Inquiry submissions that mention "bitcoin" or "coinbase" anywhere in the form (case-insensitive) as spam, so they are never written to the deal spreadsheet, logged as a Freshsales note, or emailed to sales. Signed-off-by: Tamal Saha --- pkg/server/kubedb_inquiry.go | 29 ++++++++++ pkg/server/kubedb_inquiry_test.go | 88 +++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 pkg/server/kubedb_inquiry_test.go diff --git a/pkg/server/kubedb_inquiry.go b/pkg/server/kubedb_inquiry.go index 30abb803..fb8e1406 100644 --- a/pkg/server/kubedb_inquiry.go +++ b/pkg/server/kubedb_inquiry.go @@ -59,13 +59,42 @@ func (form *KubeDBInquiryInfo) Complete() { form.CustomerCompany = strings.TrimSpace(form.CustomerCompany) } +// spamKeywords are terms that never legitimately appear in a KubeDB inquiry; +// their presence marks the submission as spam. +var spamKeywords = []string{"bitcoin", "coinbase"} + func (form KubeDBInquiryInfo) Validate() error { if !strings.Contains(form.CustomerEmail, "@") { return fmt.Errorf("invalid customer email: %s", form.CustomerEmail) } + if form.IsSpam() { + return fmt.Errorf("submission flagged as spam") + } return nil } +// IsSpam reports whether any field of the inquiry mentions a spam keyword. +func (form KubeDBInquiryInfo) IsSpam() bool { + fields := strings.ToLower(strings.Join([]string{ + form.CustomerName, + form.CustomerCompany, + form.CustomerAddress, + form.CustomerCountry, + form.EstimatedDatabaseMemory, + form.KubernetesSetup, + form.SupportPlan, + form.ProjectTimeline, + form.ProfessionalServices, + form.Notes, + }, " ")) + for _, keyword := range spamKeywords { + if strings.Contains(fields, keyword) { + return true + } + } + return false +} + func (s *Server) HandleKubeDBInquiry(info *KubeDBInquiryInfo) error { go func() { clients := []*KubeDBInquiryInfo{info} diff --git a/pkg/server/kubedb_inquiry_test.go b/pkg/server/kubedb_inquiry_test.go new file mode 100644 index 00000000..8e8ff81e --- /dev/null +++ b/pkg/server/kubedb_inquiry_test.go @@ -0,0 +1,88 @@ +/* +Copyright AppsCode Inc. + +Licensed 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 server_test + +import ( + "testing" + + "go.bytebuilders.dev/offline-license-server/pkg/server" +) + +func TestKubeDBInquiryInfo_Validate_Spam(t *testing.T) { + baseForm := func() server.KubeDBInquiryInfo { + return server.KubeDBInquiryInfo{ + CustomerName: "Jane Doe", + CustomerEmail: "jane.doe@example.com", + CustomerCompany: "Example Inc", + CustomerAddress: "123 Main St", + CustomerCountry: "USA", + Notes: "Interested in a KubeDB Enterprise quote", + } + } + + tests := []struct { + name string + mutate func(*server.KubeDBInquiryInfo) + wantSpam bool + }{ + { + name: "legitimate inquiry", + mutate: func(f *server.KubeDBInquiryInfo) {}, + wantSpam: false, + }, + { + name: "bitcoin in notes", + mutate: func(f *server.KubeDBInquiryInfo) { + f.Notes = "Please pay in bitcoin" + }, + wantSpam: true, + }, + { + name: "coinbase in notes, mixed case", + mutate: func(f *server.KubeDBInquiryInfo) { + f.Notes = "Send funds via CoinBase" + }, + wantSpam: true, + }, + { + name: "bitcoin in company name", + mutate: func(f *server.KubeDBInquiryInfo) { + f.CustomerCompany = "Bitcoin Ventures LLC" + }, + wantSpam: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + form := baseForm() + tt.mutate(&form) + + if got := form.IsSpam(); got != tt.wantSpam { + t.Errorf("IsSpam() = %v; want %v", got, tt.wantSpam) + } + + err := form.Validate() + if tt.wantSpam && err == nil { + t.Errorf("Validate() = nil; want spam error") + } + if !tt.wantSpam && err != nil { + t.Errorf("Validate() = %v; want nil", err) + } + }) + } +}