Skip to content

Commit 4db192c

Browse files
authored
Merge pull request #186 from mtruj013/cve-status-update
Update cve status options and apply updates across test fixtures
2 parents 4476587 + 894ed24 commit 4db192c

File tree

12 files changed

+94
-19
lines changed

12 files changed

+94
-19
lines changed
Binary file not shown.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""empty message
2+
3+
Revision ID: 654254322cd3
4+
Revises: 645c9424286e
5+
Create Date: 2024-12-05 15:16:32.511623
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '654254322cd3'
14+
down_revision = '645c9424286e'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
# Enum 'type' for PostgreSQL
20+
enum_name = 'cve_statuses'
21+
# Set temporary enum 'type' for PostgreSQL
22+
tmp_enum_name = 'tmp_' + enum_name
23+
24+
# Options for Enum
25+
old_options = ("not-in-ubuntu", "active", "rejected")
26+
new_options = ("not-in-ubuntu", "in-progress", "rejected")
27+
28+
# Create enum fields
29+
old_type = sa.Enum(*old_options, name=enum_name)
30+
new_type = sa.Enum(*new_options, name=enum_name)
31+
32+
def upgrade():
33+
# Rename current enum type to tmp_
34+
op.execute('ALTER TYPE ' + enum_name + ' RENAME TO ' + tmp_enum_name)
35+
# Create new enum type in db
36+
new_type.create(op.get_bind())
37+
# Update column to use new enum type
38+
op.execute('ALTER TABLE cve ALTER COLUMN status TYPE ' + enum_name + ' USING status::text::' + enum_name)
39+
# Drop old enum type
40+
op.execute('DROP TYPE ' + tmp_enum_name)
41+
42+
def downgrade():
43+
# Instantiate db query
44+
status = sa.sql.table('cve', sa.Column('status', new_type, nullable=False))
45+
# Rename enum type to tmp_
46+
op.execute('ALTER TYPE ' + enum_name + ' RENAME TO ' + tmp_enum_name)
47+
# Create enum type using old values
48+
old_type.create(op.get_bind())
49+
# Set enum type as type for status column
50+
op.execute('ALTER TABLE cve ALTER COLUMN status TYPE ' + enum_name + ' USING status::text::' + enum_name)
51+
# Drop temp enum type
52+
op.execute('DROP TYPE ' + tmp_enum_name)

scripts/generate-sample-security-data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
patches={},
5050
tags={},
5151
bugs={},
52-
status="active",
52+
status="in-progress",
5353
)
5454
db.session.add(cve)
5555
cves.append(cve)

scripts/payloads/cves.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"https://www.mozilla.org/en-US/security/advisories/mfsa2020-08/#CVE-2019-20503",
8181
"https://usn.ubuntu.com/usn/usn-4299-1"
8282
],
83-
"status": "active",
83+
"status": "in-progress",
8484
"tags": {},
8585
"ubuntu_description": ""
8686
}

tests/fixtures/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def make_cve(
3030
patches={},
3131
tags={},
3232
bugs={},
33-
status="active",
33+
status="in-progress",
3434
):
3535
cve = CVE(
3636
id=id,

tests/fixtures/payloads.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"priority": "critical",
5050
"published": "2020-08-01 12:42:54",
51+
"status": "not-in-ubuntu",
5152
}
5253

5354
cve2 = {
@@ -74,7 +75,7 @@
7475
],
7576
"published": "2020-11-01 12:42:54",
7677
"priority": "high",
77-
"status": "active",
78+
"status": "in-progress",
7879
}
7980

8081
cve3 = {
@@ -101,7 +102,7 @@
101102
],
102103
"priority": "medium",
103104
"published": "2019-12-01 12:42:54",
104-
"status": "active",
105+
"status": "in-progress",
105106
}
106107

107108
cve4 = {
@@ -127,7 +128,7 @@
127128
],
128129
"priority": "medium",
129130
"published": "2022-12-01 12:42:54",
130-
"status": "active",
131+
"status": "in-progress",
131132
}
132133

133134
cve5 = {
@@ -152,7 +153,7 @@
152153
],
153154
"published": "2020-12-01 12:42:54",
154155
"priority": "low",
155-
"status": "active",
156+
"status": "in-progress",
156157
}
157158

158159
cve6 = {
@@ -177,7 +178,7 @@
177178
],
178179
"published": "2020-12-01 12:42:54",
179180
"priority": "negligible",
180-
"status": "active",
181+
"status": "in-progress",
181182
}
182183

183184
cve7 = {
@@ -202,7 +203,7 @@
202203
],
203204
"published": "2020-12-01 12:42:54",
204205
"priority": "negligible",
205-
"status": "active",
206+
"status": "in-progress",
206207
}
207208

208209
cve8 = {
@@ -227,7 +228,7 @@
227228
],
228229
"published": "2020-12-01 12:42:54",
229230
"priority": "negligible",
230-
"status": "active",
231+
"status": "in-progress",
231232
}
232233

233234
notice = {

tests/test_routes.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,23 @@ def test_cves_query_no_500(self):
4848

4949
assert response.status_code == 200
5050

51+
def test_cves_default_status(self):
52+
# Add new CVE without status
53+
cve_payload = payloads.cve1.copy()
54+
55+
add_cve_response = self.client.put(
56+
"/security/updates/cves.json",
57+
json=[cve_payload],
58+
)
59+
60+
assert add_cve_response.status_code == 200
61+
response = self.client.get("/security/cves.json")
62+
63+
assert response.status_code == 200
64+
# Only the CVE with the default "in-progress" status should be returned
65+
assert len(response.json["cves"]) == 1
66+
assert response.json["cves"][0]["status"] == "in-progress"
67+
5168
def test_cves_returns_200_for_non_existing_package_name(self):
5269
response = self.client.get("/security/cves.json?package=no-exist")
5370

@@ -689,7 +706,7 @@ def test_cve_group_by_functionality(self):
689706
Tests that CVEs are correctly grouped by priority
690707
and ordered by publish date.
691708
"""
692-
# Check that there is one CVE in the db with an active status
709+
# Check that there is one CVE in the db with an "in-progress" status
693710
# and a critical priority
694711
initial_cves = self.client.get("/security/cves.json")
695712

webapp/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from webapp.api_spec import WebappFlaskApiSpec
99
from webapp.commands import register_commands
10-
from webapp.database import init_db
10+
from webapp.database import db, init_db # noqa: F401
1111
from webapp.views import (
1212
bulk_upsert_cve,
1313
create_notice,

webapp/models.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
Boolean,
77
Column,
88
DateTime,
9-
Enum,
109
Float,
1110
ForeignKey,
1211
JSON,
@@ -24,6 +23,7 @@
2423
COMPONENT_OPTIONS,
2524
POCKET_OPTIONS,
2625
PRIORITY_OPTIONS,
26+
CVE_STATUSES,
2727
)
2828

2929

@@ -63,9 +63,7 @@ class CVE(db.Model):
6363
patches = Column(JSON)
6464
tags = Column(JSON)
6565
bugs = Column(JSON)
66-
status = Column(
67-
Enum("not-in-ubuntu", "active", "rejected", name="cve_statuses")
68-
)
66+
status = Column(CVE_STATUSES)
6967
statuses = relationship("Status", cascade="all, delete-orphan")
7068
notices = relationship(
7169
"Notice", secondary=notice_cves, back_populates="cves"

webapp/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ class CVEsAPISchema(Schema):
529529
),
530530
"cve_status": String(
531531
description="CVE status",
532-
enum=["not-in-ubuntu", "active", "rejected"],
532+
enum=["not-in-ubuntu", "in-progress", "rejected"],
533533
allow_none=True,
534534
),
535535
"status": List(

webapp/types.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@
4949
"critical",
5050
name="priorities",
5151
)
52+
53+
CVE_STATUSES = Enum(
54+
"not-in-ubuntu",
55+
"in-progress",
56+
"rejected",
57+
name="cve_statuses",
58+
)

webapp/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ def get_cves(**kwargs):
104104
sort_by = kwargs.get("sort_by")
105105
show_hidden = kwargs.get("show_hidden", False)
106106

107-
# query cves by filters. Default filter by active CVEs
107+
# query cves by filters. Default filter by "in-progress" CVEs
108108
if cve_status:
109109
cves_query: Query = db.session.query(CVE).filter(
110110
CVE.status == cve_status
111111
)
112112
else:
113113
cves_query: Query = db.session.query(CVE).filter(
114-
CVE.status == "active"
114+
CVE.status == "in-progress"
115115
)
116116

117117
# order by priority

0 commit comments

Comments
 (0)