/
data_types.py
1397 lines (996 loc) · 40.9 KB
/
data_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2019 Google LLC
#
# 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.
"""Classes for objects stored in the datastore."""
# IMPORTANT: If you modify this file, please run
# `python butler.py generate_datastore_models`
# to generate Go structs for the models defined here.
from builtins import object
import re
import six
from base import json_utils
from base import utils
from datastore import ndb
from datastore import search_tokenizer
from metrics import logs
from system import environment
# Prefix used when a large testcase is stored in the blobstore.
BLOBSTORE_STACK_PREFIX = 'BLOB_KEY='
# List of builtin fuzzers.
BUILTIN_FUZZERS = ['afl', 'libFuzzer']
# Time to look back to find a corpus backup that is marked public.
CORPUS_BACKUP_PUBLIC_LOOKBACK_DAYS = 90
# Marker to indicate end of crash stacktrace. Anything after that is excluded
# from being stored as part of crash stacktrace (e.g. merge content, etc).
CRASH_STACKTRACE_END_MARKER = 'CRASH OUTPUT ENDS HERE'
# Skips using crash state similarity for these types.
CRASH_TYPES_WITH_UNIQUE_STATE = [
'Hang',
'Timeout',
'Out-of-memory',
# V8 correctness failures use metadata from the fuzz test cases as crash
# state. This is not suitable for using levenshtein distance for
# similarity.
'V8 correctness failure',
]
# Maximum size allowed for an appengine entity type.
# Explicily kept slightly lower than 1 MB.
ENTITY_SIZE_LIMIT = 900000
# Minimum number of unreproducible crashes to see before filing it.
FILE_UNREPRODUCIBLE_TESTCASE_MIN_CRASH_THRESHOLD = 100
# Heartbeat wait interval.
HEARTBEAT_WAIT_INTERVAL = 10 * 60
# FIXME: Move this to configuration.
# List of internal sandboxed data types. This gives a warning on testcase
# uploads on unsandboxed job types.
INTERNAL_SANDBOXED_JOB_TYPES = [
'linux_asan_chrome_media', 'linux_asan_chrome_mp',
'linux_asan_chrome_v8_arm', 'mac_asan_chrome', 'windows_asan_chrome'
]
# Time to wait after a report is marked fixed and before filing another similar
# one (hours).
MIN_ELAPSED_TIME_SINCE_FIXED = 2 * 24
# Time to wait for grouping task to finish, before filing the report (hours).
MIN_ELAPSED_TIME_SINCE_REPORT = 3
# Valid name check for fuzzer, job, etc.
NAME_CHECK_REGEX = re.compile(r'^[a-zA-Z0-9_-]+$')
# Regex to match special chars in project name.
SPECIAL_CHARS_REGEX = re.compile('[^a-zA-Z0-9_-]')
# List of supported platforms.
PLATFORMS = [
'LINUX',
'ANDROID',
'CHROMEOS',
'MAC',
'WINDOWS',
'FUCHSIA',
]
# Maximum size allowed for an appengine pubsub request.
# Explicily kept slightly lower than 1 MB.
PUBSUB_REQUEST_LIMIT = 900000
# We store at most 3 stacktraces per Testcase entity (original, second, latest).
STACKTRACE_LENGTH_LIMIT = ENTITY_SIZE_LIMIT // 3
# Maximum size allowed for testcase comments.
# 1MiB (maximum Datastore entity size) - ENTITY_SIZE_LIMIT (our limited entity
# size with breathing room), divided by 2 to leave room for other things in the
# entity. This is around 74KB.
TESTCASE_COMMENTS_LENGTH_LIMIT = (1024 * 1024 - ENTITY_SIZE_LIMIT) // 2
# Maximum number of testcase entities to query in one batch.
TESTCASE_ENTITY_QUERY_LIMIT = 256
# Deadlines for testcase filing, closures and deletions (in days).
DUPLICATE_TESTCASE_NO_BUG_DEADLINE = 30
CLOSE_TESTCASE_WITH_CLOSED_BUG_DEADLINE = 14
FILE_CONSISTENT_UNREPRODUCIBLE_TESTCASE_DEADLINE = 14
NOTIFY_CLOSED_BUG_WITH_OPEN_TESTCASE_DEADLINE = 7
UNREPRODUCIBLE_TESTCASE_NO_BUG_DEADLINE = 7
UNREPRODUCIBLE_TESTCASE_WITH_BUG_DEADLINE = 14
# Chromium specific issue state tracking labels.
CHROMIUM_ISSUE_RELEASEBLOCK_BETA_LABEL = 'ReleaseBlock-Beta'
# TODO(ochang): Find some way to remove these.
CHROMIUM_ISSUE_PREDATOR_AUTO_CC_LABEL = 'Test-Predator-Auto-CC'
CHROMIUM_ISSUE_PREDATOR_AUTO_COMPONENTS_LABEL = 'Test-Predator-Auto-Components'
CHROMIUM_ISSUE_PREDATOR_AUTO_OWNER_LABEL = 'Test-Predator-Auto-Owner'
CHROMIUM_ISSUE_PREDATOR_WRONG_COMPONENTS_LABEL = (
'Test-Predator-Wrong-Components')
CHROMIUM_ISSUE_PREDATOR_WRONG_CL_LABEL = 'Test-Predator-Wrong-CLs'
MISSING_VALUE_STRING = '---'
# FIXME: Move these "enums" into seperate file(s).
class SecuritySeverity(object):
"""Enum for Security Severity."""
CRITICAL = 0
HIGH = 1
MEDIUM = 2
LOW = 3
MISSING = 4
@classmethod
def is_valid(cls, security_severity):
"""Return bool on whether a severity is valid."""
return (security_severity in [cls.CRITICAL, cls.HIGH, cls.MEDIUM, cls.LOW])
@classmethod
def list(cls):
"""Return the list of severities for a dropdown menu."""
return [
{
'value': cls.CRITICAL,
'name': 'Critical'
},
{
'value': cls.HIGH,
'name': 'High',
'default': True
},
{
'value': cls.MEDIUM,
'name': 'Medium'
},
{
'value': cls.LOW,
'name': 'Low'
},
{
'value': cls.MISSING,
'name': 'Missing'
},
]
# Impact values for security issues.
class SecurityImpact(object):
STABLE = 0
BETA = 1
HEAD = 2
NONE = 3
MISSING = 4
# Archive state enums.
class ArchiveStatus(object):
NONE = 0
FUZZED = 1
MINIMIZED = 2
ALL = FUZZED | MINIMIZED
# ExternalUserPermission Auto-CC type.
class AutoCCType(object):
# Don't Auto-CC user.
NONE = 0
# Auto-CC user for all issues.
ALL = 1
# Auto-CC only for security issues.
SECURITY = 2
# Type of permission. Used by ExternalUserPermision.
class PermissionEntityKind(object):
FUZZER = 0
JOB = 1
# Task state string mappings.
class TaskState(object):
STARTED = 'started'
WIP = 'in-progress'
FINISHED = 'finished'
ERROR = 'errored out'
NA = ''
# Build state.
class BuildState(object):
UNMARKED = 0
GOOD = 1
BAD = 2
class TestcaseVariantStatus(object):
PENDING = 0
REPRODUCIBLE = 1
FLAKY = 2
UNREPRODUCIBLE = 3
class Model(ndb.Model):
"""Cache-less NDB model."""
_use_cache = False
_use_memcache = False
class Blacklist(Model):
"""Represents global blacklist to track entries for suppressions files."""
# Function name.
function_name = ndb.StringProperty()
# Tool name.
tool_name = ndb.StringProperty()
# Testcase ID.
testcase_id = ndb.IntegerProperty()
class Fuzzer(Model):
"""Represents a fuzzer."""
VALID_NAME_REGEX = NAME_CHECK_REGEX
# Last update time.
timestamp = ndb.DateTimeProperty()
# Fuzzer Name.
name = ndb.StringProperty()
# The name of the archive that the user uploaded.
filename = ndb.StringProperty()
# Blobstore key for this fuzzer.
blobstore_key = ndb.StringProperty()
# String representation of the file size.
file_size = ndb.StringProperty()
# Fuzzer's main executable path, relative to root.
executable_path = ndb.StringProperty()
# Revision number of the fuzzer.
revision = ndb.IntegerProperty()
# Fuzzer's source (for accountability).
source = ndb.StringProperty()
# Testcase timeout.
timeout = ndb.IntegerProperty()
# Supported platforms.
supported_platforms = ndb.StringProperty()
# Custom script that should be used to launch chrome for this fuzzer.
launcher_script = ndb.StringProperty()
# Result from the last fuzzer run showing the number of testcases generated.
result = ndb.StringProperty()
# Last result update timestamp.
result_timestamp = ndb.DateTimeProperty()
# Console output from last fuzzer run.
console_output = ndb.TextProperty()
# Return code from last fuzzer run.
return_code = ndb.IntegerProperty()
# Blobstore key for the sample testcase generated by the fuzzer.
sample_testcase = ndb.StringProperty()
# Job types for this fuzzer.
jobs = ndb.StringProperty(repeated=True)
# Is the fuzzer coming from an external contributor ? Useful for adding
# reward flags.
external_contribution = ndb.BooleanProperty(default=False)
# Max testcases to generate for this fuzzer.
max_testcases = ndb.IntegerProperty()
# Does it run un-trusted content ? Examples including running live sites.
untrusted_content = ndb.BooleanProperty(default=False)
# Data bundle name.
data_bundle_name = ndb.StringProperty(default='')
# Additional environment variables that need to be set for this fuzzer.
additional_environment_string = ndb.TextProperty()
# Column specification for stats.
stats_columns = ndb.StringProperty(indexed=False)
# Helpful descriptions for the stats_columns. In a yaml format.
stats_column_descriptions = ndb.TextProperty(indexed=False)
# Whether this is a builtin fuzzer.
builtin = ndb.BooleanProperty(indexed=False, default=False)
# Whether this is a differential fuzzer.
differential = ndb.BooleanProperty(default=False)
class BuildCrashStatsJobHistory(Model):
"""Represents the record of build_crash_stats run."""
# End time in hours from epoch, inclusively.
end_time_in_hours = ndb.IntegerProperty()
class Testcase(Model):
"""Represents a single testcase."""
# Crash on an invalid read/write.
crash_type = ndb.StringProperty()
# Crashing address.
crash_address = ndb.StringProperty(indexed=False)
# First x stack frames.
crash_state = ndb.StringProperty()
# Complete stacktrace.
crash_stacktrace = ndb.TextProperty(indexed=False)
# Last tested crash stacktrace using the latest revision.
last_tested_crash_stacktrace = ndb.TextProperty(indexed=False)
# Blobstore keys for various things like original testcase, minimized
# testcase, etc.
fuzzed_keys = ndb.StringProperty(indexed=False)
minimized_keys = ndb.StringProperty(indexed=False)
minidump_keys = ndb.StringProperty(indexed=False)
# Tracking issue tracker bug. One bug number per line (future extension).
bug_information = ndb.StringProperty()
# Regression range.
regression = ndb.StringProperty(default='')
# Revisions where this issue has been fixed.
fixed = ndb.StringProperty(default='')
# Is it a security bug ?
security_flag = ndb.BooleanProperty(default=False)
# Security severity of the bug.
security_severity = ndb.IntegerProperty(indexed=False)
# Did the bug only reproduced once ?
one_time_crasher_flag = ndb.BooleanProperty(default=False)
# Any additional comments.
comments = ndb.TextProperty(default='', indexed=False)
# Revision that we discovered the crash in.
crash_revision = ndb.IntegerProperty()
# The file on the bot that generated the testcase.
original_absolute_path = ndb.StringProperty(indexed=False, default='')
absolute_path = ndb.StringProperty(indexed=False)
# Minimized argument list.
minimized_arguments = ndb.TextProperty(default='', indexed=False)
# Window argument (usually width, height, top, left, etc).
window_argument = ndb.TextProperty(default='', indexed=False)
# Type of job associated with this testcase.
job_type = ndb.StringProperty()
# Original job queue used for tasks created for this testcase.
queue = ndb.StringProperty(indexed=False)
# State representing whether the fuzzed or minimized testcases are archived.
archive_state = ndb.IntegerProperty(default=0, indexed=False)
# File name of the original uploaded archive.
archive_filename = ndb.StringProperty(indexed=False)
# Is this a binary file?
binary_flag = ndb.BooleanProperty(default=False, indexed=False)
# Timestamp.
timestamp = ndb.DateTimeProperty()
# Does the testcase crash stack vary b/w crashes ?
flaky_stack = ndb.BooleanProperty(default=False, indexed=False)
# Do we need to test this testcase using an HTTP/HTTPS server?
http_flag = ndb.BooleanProperty(default=False, indexed=False)
# Name of the fuzzer used to generate this testcase.
fuzzer_name = ndb.StringProperty()
# Status of this testcase (pending, processed, unreproducible, etc).
status = ndb.StringProperty(default='Processed')
# Id of the testcase that this is marked as a duplicate of.
duplicate_of = ndb.IntegerProperty(indexed=False)
# Flag indicating whether or not the testcase has been symbolized.
symbolized = ndb.BooleanProperty(default=False, indexed=False)
# Id for this testcase's associated group.
group_id = ndb.IntegerProperty(default=0)
# Tracking issue tracker bug for this testcase group.
group_bug_information = ndb.IntegerProperty(default=0)
# Fake user interaction sequences like key clicks, mouse movements, etc.
gestures = ndb.StringProperty(repeated=True, indexed=False)
# ASAN redzone size in bytes.
redzone = ndb.IntegerProperty(default=128, indexed=False)
# Whether testcase is open.
open = ndb.BooleanProperty(default=True)
# Adjusts timeout based on multiplier value.
timeout_multiplier = ndb.FloatProperty(default=1.0, indexed=False)
# Additional metadata stored as a JSON object. This should be used for
# properties that are not commonly accessed and do not need to be indexed.
additional_metadata = ndb.TextProperty(indexed=False)
# Boolean attribute indicating if cleanup triage needs to be done.
triaged = ndb.BooleanProperty(default=False)
# Project name associated with this test case.
project_name = ndb.StringProperty()
# keywords is used for searching.
keywords = ndb.StringProperty(repeated=True)
# Whether testcase has a bug (either bug_information or
# group_bug_information).
has_bug_flag = ndb.BooleanProperty()
# Indices for bug_information and group_bug_information.
bug_indices = ndb.StringProperty(repeated=True)
# Overridden fuzzer name because actual fuzzer name can be different in many
# scenarios (libfuzzer, afl, etc).
overridden_fuzzer_name = ndb.StringProperty()
# Platform (e.g. windows, linux, android).
platform = ndb.StringProperty()
# Platform id (e.g. windows, linux, android:hammerhead:l).
# For Android, includes device type and underlying OS version.
platform_id = ndb.StringProperty()
# Impact indices for searching.
impact_indices = ndb.StringProperty(repeated=True)
# Whether or not a testcase is a duplicate of other testcase.
is_a_duplicate_flag = ndb.BooleanProperty()
# Whether or not a testcase is the leader of its group.
# If the testcase is not in a group, it's the leader of a group of 1.
# The default is false because we prefer not to show crashes until we are
# sure. And group_task will correctly set the value within 30 minutes.
is_leader = ndb.BooleanProperty(default=False)
# Fuzzer name indices
fuzzer_name_indices = ndb.StringProperty(repeated=True)
# The impacted version indices (including both beta and stable).
impact_version_indices = ndb.StringProperty(repeated=True)
# The impacted stable version.
impact_stable_version = ndb.StringProperty()
# The impacted stable version indices.
impact_stable_version_indices = ndb.StringProperty(repeated=True)
# The impacted stable version is merely probable (not definite). Because
# for a non-asan build, we don't have a stable/beta build. Therefore, we
# make an intelligent guess on the version.
impact_stable_version_likely = ndb.BooleanProperty()
# The impacted beta version.
impact_beta_version = ndb.StringProperty()
# The impacted beta version indices.
impact_beta_version_indices = ndb.StringProperty(repeated=True)
# The impacted beta version is merely probable (not definite). See the
# comment on impact_stable_version_likely.
impact_beta_version_likely = ndb.BooleanProperty()
# Whether or not impact task has been run on this testcase.
is_impact_set_flag = ndb.BooleanProperty()
# Code coverage data for the testcase.
coverage = ndb.StringProperty()
# Uploader email address.
uploader_email = ndb.StringProperty()
def has_blame(self):
return self.project_name == 'chromium'
def has_impacts(self):
return self.project_name == 'chromium' and not self.one_time_crasher_flag
def impacts_production(self):
return bool(self.impact_stable_version) or bool(self.impact_beta_version)
def is_status_unreproducible(self):
return self.status and self.status.startswith('Unreproducible')
def is_crash(self):
return bool(self.crash_state)
def populate_indices(self):
"""Populate keywords for fast test case list searching."""
self.keywords = list(
search_tokenizer.tokenize(self.crash_state)
| search_tokenizer.tokenize(self.crash_type)
| search_tokenizer.tokenize(self.fuzzer_name)
| search_tokenizer.tokenize(self.overridden_fuzzer_name)
| search_tokenizer.tokenize(self.job_type)
| search_tokenizer.tokenize(self.platform_id))
self.bug_indices = search_tokenizer.tokenize_bug_information(self)
self.has_bug_flag = bool(self.bug_indices)
self.is_a_duplicate_flag = bool(self.duplicate_of)
fuzzer_name_indices = list(
set([self.fuzzer_name, self.overridden_fuzzer_name]))
self.fuzzer_name_indices = [f for f in fuzzer_name_indices if f]
# If the impact task hasn't been run (aka is_impact_set_flag=False) OR
# if impact isn't applicable (aka has_impacts() is False), we wipe all
# the impact fields' indices.
if self.has_impacts() and self.is_impact_set_flag:
self.impact_stable_version_indices = (
search_tokenizer.tokenize_impact_version(self.impact_stable_version))
self.impact_beta_version_indices = (
search_tokenizer.tokenize_impact_version(self.impact_beta_version))
self.impact_version_indices = list(
set(self.impact_stable_version_indices +
self.impact_beta_version_indices))
if self.impact_beta_version:
self.impact_version_indices.append('beta')
if self.impact_stable_version:
self.impact_version_indices.append('stable')
if not self.impacts_production():
self.impact_version_indices.append('head')
else:
self.impact_version_indices = []
self.impact_stable_version_indices = []
self.impact_beta_version_indices = []
def _pre_put_hook(self):
self.populate_indices()
def _post_put_hook(self, _):
logs.log('Updated testcase %d (bug %s).' % (self.key.id(),
self.bug_information or '-'))
def set_impacts_as_na(self):
self.impact_stable_version = self.impact_beta_version = None
self.impact_stable_version_likely = self.impact_beta_version_likely = False
self.is_impact_set_flag = False
def _ensure_metadata_is_cached(self):
"""Ensure that the metadata for this has been cached."""
if hasattr(self, 'metadata_cache'):
return
try:
cache = json_utils.loads(self.additional_metadata)
except (TypeError, ValueError):
cache = {}
setattr(self, 'metadata_cache', cache)
def get_metadata(self, key=None, default=None):
"""Get metadata for a test case. Slow on first access."""
self._ensure_metadata_is_cached()
# If no key is specified, return all metadata.
if not key:
return self.metadata_cache
try:
return self.metadata_cache[key]
except KeyError:
return default
def set_metadata(self, key, value, update_testcase=True):
"""Set metadata for a test case."""
self._ensure_metadata_is_cached()
self.metadata_cache[key] = value
self.additional_metadata = json_utils.dumps(self.metadata_cache)
if update_testcase:
self.put()
def delete_metadata(self, key, update_testcase=True):
"""Remove metadata key for a test case."""
self._ensure_metadata_is_cached()
# Make sure that the key exists in cache. If not, no work to do here.
if key not in self.metadata_cache:
return
del self.metadata_cache[key]
self.additional_metadata = json_utils.dumps(self.metadata_cache)
if update_testcase:
self.put()
def actual_fuzzer_name(self):
"""Actual fuzzer name, uses one from overridden attribute if available."""
return self.overridden_fuzzer_name or self.fuzzer_name
def get_fuzz_target(self):
"""Get the associated FuzzTarget entity for this test case."""
name = self.actual_fuzzer_name()
if not name:
return None
return ndb.Key(FuzzTarget, name).get()
class TestcaseGroup(Model):
"""Group for a set of testcases."""
pass
class DataBundle(Model):
"""Represents a data bundle associated with a fuzzer."""
VALID_NAME_REGEX = NAME_CHECK_REGEX
# The data bundle's name (important for identifying shared bundles).
name = ndb.StringProperty()
# Name of cloud storage bucket on GCS.
bucket_name = ndb.StringProperty()
# Data bundle's source (for accountability).
# TODO(ochang): Remove.
source = ndb.StringProperty()
# If data bundle can be unpacked locally or needs nfs.
is_local = ndb.BooleanProperty(default=True)
# Creation timestamp.
timestamp = ndb.DateTimeProperty()
# Whether or not bundle should be synced to worker instead.
# Fuzzer scripts are usually run on trusted hosts, so data bundles are synced
# there. In libFuzzer's case, we want the bundle to be on the same machine as
# where the libFuzzer binary will run (untrusted).
sync_to_worker = ndb.BooleanProperty(default=False)
class Config(Model):
"""Configuration."""
previous_hash = ndb.StringProperty(default='')
# Project's url.
url = ndb.StringProperty(default='')
# Issue tracker client authentication parameters.
client_credentials = ndb.TextProperty(default='')
# Build apiary authentication parameters.
build_apiary_service_account_email = ndb.StringProperty(default='')
build_apiary_service_account_private_key = ndb.TextProperty(default='')
# Google test account for login, gms testing, etc.
test_account_email = ndb.StringProperty(default='')
test_account_password = ndb.StringProperty(default='')
# Privileged users.
privileged_users = ndb.TextProperty(default='')
# Admin contact string.
contact_string = ndb.StringProperty(default='')
# Component to repository mappings.
component_repository_mappings = ndb.TextProperty(default='')
# URL for help page for reproducing issues.
reproduction_help_url = ndb.StringProperty(default='')
# Documentation url.
documentation_url = ndb.StringProperty(default='')
# Bug report url.
bug_report_url = ndb.StringProperty(default='')
# Platforms that coverage is supported for.
platform_group_mappings = ndb.TextProperty(default='')
# More relaxed restrictions: allow CC'ed users and reporters of issues to view
# testcase details.
relax_testcase_restrictions = ndb.BooleanProperty(default=False)
# More relaxed restrictions: allow domain users to access both security and
# functional bugs.
relax_security_bug_restrictions = ndb.BooleanProperty(default=False)
# Coverage reports bucket.
coverage_reports_bucket = ndb.StringProperty(default='')
# For GitHub API.
github_credentials = ndb.StringProperty(default='')
# OAuth2 client id for the reproduce tool.
reproduce_tool_client_id = ndb.StringProperty(default='')
# OAuth2 client secret for the reproduce tool.
reproduce_tool_client_secret = ndb.StringProperty(default='')
# Pub/Sub topics for the Predator service.
predator_crash_topic = ndb.StringProperty(default='')
predator_result_topic = ndb.StringProperty(default='')
# Wifi connection information.
wifi_ssid = ndb.StringProperty(default='')
wifi_password = ndb.StringProperty(default='')
# SendGrid config.
sendgrid_api_key = ndb.StringProperty(default='')
sendgrid_sender = ndb.StringProperty(default='')
class TestcaseUploadMetadata(Model):
"""Metadata associated with a user uploaded test case."""
# Timestamp.
timestamp = ndb.DateTimeProperty()
# Testcase filename.
filename = ndb.StringProperty()
# Current status of the testcase.
status = ndb.StringProperty()
# Uploader email address.
uploader_email = ndb.StringProperty()
# Name of the bot that ran analyze on this testcase.
bot_name = ndb.StringProperty()
# Id of the associated testcase.
testcase_id = ndb.IntegerProperty()
# Id of the testcase that this is marked as a duplicate of.
duplicate_of = ndb.IntegerProperty()
# Blobstore key for the testcase associated with this object.
blobstore_key = ndb.StringProperty()
# Testcase timeout.
timeout = ndb.IntegerProperty()
# Is this a single testcase bundled in an archive?
bundled = ndb.BooleanProperty()
# Path to the file in the archive.
path_in_archive = ndb.TextProperty()
# Original blobstore key for this object (used for archives).
original_blobstore_key = ndb.StringProperty()
# Security flag.
security_flag = ndb.BooleanProperty(default=False)
# Number of retries for this testcase.
retries = ndb.IntegerProperty()
# Flag to indicate where bug title should be updated or not.
bug_summary_update_flag = ndb.BooleanProperty()
# Flag to indicate if we are running in quiet mode (e.g. bug updates).
quiet_flag = ndb.BooleanProperty()
class JobTemplate(Model):
# Job template name.
name = ndb.StringProperty()
# Environment string.
environment_string = ndb.TextProperty()
class Job(Model):
"""Definition of a job type used by the bots."""
VALID_NAME_REGEX = NAME_CHECK_REGEX
# Job type name.
name = ndb.StringProperty()
# Job environment string.
environment_string = ndb.TextProperty()
# The platform that this job can run on.
platform = ndb.StringProperty()
# Blobstore key of the custom binary for this job.
custom_binary_key = ndb.StringProperty()
# Filename for the custom binary.
custom_binary_filename = ndb.StringProperty()
# Revision of the custom binary.
custom_binary_revision = ndb.IntegerProperty()
# Description of the job.
description = ndb.TextProperty()
# Template to use, if any.
templates = ndb.StringProperty(repeated=True)
def get_environment(self):
"""Get the environment as a dict for this job, including any environment
variables in its template."""
if not self.templates:
return environment.parse_environment_definition(self.environment_string)
job_environment = {}
for template_name in self.templates:
template = JobTemplate.query(JobTemplate.name == template_name).get()
if not template:
continue
template_environment = environment.parse_environment_definition(
template.environment_string)
job_environment.update(template_environment)
environment_overrides = environment.parse_environment_definition(
self.environment_string)
job_environment.update(environment_overrides)
return job_environment
def get_environment_string(self):
"""Get the environment string for this job, including any environment
variables in its template. Avoid using this if possible."""
environment_string = ''
job_environment = self.get_environment()
for key, value in six.iteritems(job_environment):
environment_string += '%s = %s\n' % (key, value)
return environment_string
class CSRFToken(Model):
"""Token used to prevent CSRF attacks."""
# Value of this token.
value = ndb.StringProperty()
# Expiration time for this token.
expiration_time = ndb.DateTimeProperty()
# User that this token is associated with.
user_email = ndb.StringProperty()
class Heartbeat(Model):
"""Bot health metadata."""
# Name of the bot.
bot_name = ndb.StringProperty()
# Time of the last heartbeat.
last_beat_time = ndb.DateTimeProperty()
# Task payload containing information on current task execution.
task_payload = ndb.StringProperty()
# Expected end time for task.
task_end_time = ndb.DateTimeProperty()
# Source version (for accountability).
source_version = ndb.StringProperty()
class Notification(Model):
"""Tracks whether or not an email has been sent to a user for a test case."""
# Testcase id associated with this notification.
testcase_id = ndb.IntegerProperty()
# User that this notification was sent to.
user_email = ndb.StringProperty()
class BundledArchiveMetadata(Model):
"""Metadata needed for multiple test cases uploaded in an archive."""
# Blobstore key of the archive.
blobstore_key = ndb.StringProperty()
# Timeout in seconds for each testcase in the bundle.
timeout = ndb.IntegerProperty()
# Job queue for the analyze tasks created for this bundle.
job_queue = ndb.StringProperty()
# Job type that should be used for all testcases in this bundle.
job_type = ndb.StringProperty()
# Flag indicating whether or not these testcases need http.
http_flag = ndb.BooleanProperty()
# File name of the uploaded archive.
archive_filename = ndb.StringProperty()
# Email address of the uploader of the archive.
uploader_email = ndb.StringProperty()
# Fake user interaction sequences like key clicks, mouse movements, etc.
gestures = ndb.StringProperty(repeated=True)
# Optional. Revision that we discovered the crash in.
crash_revision = ndb.IntegerProperty()
# Optional. Additional arguments.
additional_arguments = ndb.StringProperty()
# Optional. Bug information.
bug_information = ndb.StringProperty()
# Optional. Platform id, e.g. android:shamu.
platform_id = ndb.StringProperty()
# Optional. App launch command. e.g. shell am start ...
app_launch_command = ndb.StringProperty()
# Fuzzer name.
fuzzer_name = ndb.StringProperty()
# Overridden fuzzer name because actual fuzzer name can be different in many
# scenarios (libfuzzer, afl, etc).
overridden_fuzzer_name = ndb.StringProperty()
# Binary name for fuzz target (only applicable to libFuzzer, AFL).
fuzzer_binary_name = ndb.StringProperty()
class TaskStatus(Model):
"""Information about task status."""
# Bot name.
bot_name = ndb.StringProperty()
# Status.
status = ndb.StringProperty()
# Time of creation or last update time.
time = ndb.DateTimeProperty()
class BuildMetadata(Model):
"""Metadata associated with a particular archived build."""
# Job type that this build belongs to.
job_type = ndb.StringProperty()
# Revision of the build.
revision = ndb.IntegerProperty()
# Good build or bad build.
bad_build = ndb.BooleanProperty(default=False)
# Stdout and stderr.
console_output = ndb.TextProperty()