Allow multiple threat types in the Spec11ThreatMatch table (#650)

* Update to generic Spec11ThreatMatch table

* Fix SQL syntax

* Make changes to the schema and add a test for null and empty threatTypes

* Fix a small typo

* Change the exception thrown with illegal arguments

Change the import for isNullOrEmpty

* Fix import for checkArgument

* Added a threat to test multiple threat types
This commit is contained in:
Legina Chen 2020-06-26 10:35:00 -07:00 committed by GitHub
parent 74b2de5c35
commit 5c5b6b20ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 129 additions and 56 deletions

View file

@ -0,0 +1,31 @@
-- Copyright 2020 The Nomulus Authors. All Rights Reserved.
--
-- 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.
alter table if exists "SafeBrowsingThreat"
rename to "Spec11ThreatMatch";
alter table if exists "Spec11ThreatMatch"
alter column "threat_type" type text[] using threat_type::text[];
alter table if exists "Spec11ThreatMatch"
rename column "threat_type" to "threat_types";
alter index if exists "safebrowsing_threat_registrar_id_idx"
rename to "spec11threatmatch_registrar_id_idx";
alter index if exists "safebrowsing_threat_tld_idx"
rename to "spec11threatmatch_tld_idx";
alter index if exists "safebrowsing_threat_check_date_idx"
rename to "spec11threatmatch_check_date_idx";

View file

@ -408,13 +408,13 @@ create sequence history_id_sequence start 1 increment 1;
primary key (revision_id)
);
create table "SafeBrowsingThreat" (
create table "Spec11ThreatMatch" (
id bigserial not null,
check_date text not null,
domain_name text not null,
domain_repo_id text not null,
registrar_id text not null,
threat_type text not null,
threat_types text[] not null,
tld text not null,
primary key (id)
);
@ -459,9 +459,9 @@ create index idx_registry_lock_registrar_id on "RegistryLock" (registrar_id);
alter table if exists "RegistryLock"
add constraint idx_registry_lock_repo_id_revision_id unique (repo_id, revision_id);
create index reservedlist_name_idx on "ReservedList" (name);
create index safebrowsing_threat_registrar_id_idx on "SafeBrowsingThreat" (registrar_id);
create index safebrowsing_threat_tld_idx on "SafeBrowsingThreat" (tld);
create index safebrowsing_threat_check_date_idx on "SafeBrowsingThreat" (check_date);
create index spec11threatmatch_registrar_id_idx on "Spec11ThreatMatch" (registrar_id);
create index spec11threatmatch_tld_idx on "Spec11ThreatMatch" (tld);
create index spec11threatmatch_check_date_idx on "Spec11ThreatMatch" (check_date);
alter table if exists "ClaimsEntry"
add constraint FK6sc6at5hedffc0nhdcab6ivuq

View file

@ -657,16 +657,16 @@ ALTER SEQUENCE public."ReservedList_revision_id_seq" OWNED BY public."ReservedLi
--
-- Name: SafeBrowsingThreat; Type: TABLE; Schema: public; Owner: -
-- Name: Spec11ThreatMatch; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public."SafeBrowsingThreat" (
CREATE TABLE public."Spec11ThreatMatch" (
id bigint NOT NULL,
check_date text NOT NULL,
domain_name text NOT NULL,
domain_repo_id text NOT NULL,
registrar_id text NOT NULL,
threat_type text NOT NULL,
threat_types text[] NOT NULL,
tld text NOT NULL
);
@ -687,7 +687,7 @@ CREATE SEQUENCE public."SafeBrowsingThreat_id_seq"
-- Name: SafeBrowsingThreat_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public."SafeBrowsingThreat_id_seq" OWNED BY public."SafeBrowsingThreat".id;
ALTER SEQUENCE public."SafeBrowsingThreat_id_seq" OWNED BY public."Spec11ThreatMatch".id;
--
@ -747,10 +747,10 @@ ALTER TABLE ONLY public."ReservedList" ALTER COLUMN revision_id SET DEFAULT next
--
-- Name: SafeBrowsingThreat id; Type: DEFAULT; Schema: public; Owner: -
-- Name: Spec11ThreatMatch id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat" ALTER COLUMN id SET DEFAULT nextval('public."SafeBrowsingThreat_id_seq"'::regclass);
ALTER TABLE ONLY public."Spec11ThreatMatch" ALTER COLUMN id SET DEFAULT nextval('public."SafeBrowsingThreat_id_seq"'::regclass);
--
@ -906,10 +906,10 @@ ALTER TABLE ONLY public."ReservedList"
--
-- Name: SafeBrowsingThreat SafeBrowsingThreat_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: Spec11ThreatMatch SafeBrowsingThreat_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat"
ALTER TABLE ONLY public."Spec11ThreatMatch"
ADD CONSTRAINT "SafeBrowsingThreat_pkey" PRIMARY KEY (id);
@ -1175,24 +1175,24 @@ CREATE INDEX reservedlist_name_idx ON public."ReservedList" USING btree (name);
--
-- Name: safebrowsing_threat_check_date_idx; Type: INDEX; Schema: public; Owner: -
-- Name: spec11threatmatch_check_date_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX safebrowsing_threat_check_date_idx ON public."SafeBrowsingThreat" USING btree (check_date);
CREATE INDEX spec11threatmatch_check_date_idx ON public."Spec11ThreatMatch" USING btree (check_date);
--
-- Name: safebrowsing_threat_registrar_id_idx; Type: INDEX; Schema: public; Owner: -
-- Name: spec11threatmatch_registrar_id_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX safebrowsing_threat_registrar_id_idx ON public."SafeBrowsingThreat" USING btree (registrar_id);
CREATE INDEX spec11threatmatch_registrar_id_idx ON public."Spec11ThreatMatch" USING btree (registrar_id);
--
-- Name: safebrowsing_threat_tld_idx; Type: INDEX; Schema: public; Owner: -
-- Name: spec11threatmatch_tld_idx; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX safebrowsing_threat_tld_idx ON public."SafeBrowsingThreat" USING btree (tld);
CREATE INDEX spec11threatmatch_tld_idx ON public."Spec11ThreatMatch" USING btree (tld);
--
@ -1460,18 +1460,18 @@ ALTER TABLE ONLY public."PollMessage"
--
-- Name: SafeBrowsingThreat fk_safebrowsing_threat_domain_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: Spec11ThreatMatch fk_safebrowsing_threat_domain_repo_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat"
ALTER TABLE ONLY public."Spec11ThreatMatch"
ADD CONSTRAINT fk_safebrowsing_threat_domain_repo_id FOREIGN KEY (domain_repo_id) REFERENCES public."Domain"(repo_id);
--
-- Name: SafeBrowsingThreat fk_safebrowsing_threat_registrar_id; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: Spec11ThreatMatch fk_safebrowsing_threat_registrar_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public."SafeBrowsingThreat"
ALTER TABLE ONLY public."Spec11ThreatMatch"
ADD CONSTRAINT fk_safebrowsing_threat_registrar_id FOREIGN KEY (registrar_id) REFERENCES public."Registrar"(registrar_id);