Skip to content

Commit fbb2040

Browse files
authored
Feedback from last live_test PR (#39)
1 parent 7ec445d commit fbb2040

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

manage.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,10 @@ def live_test(self):
125125
)
126126

127127
table_name = '{}_binaryalert_matches'.format(self._config['name_prefix'])
128-
print('EICAR test file uploaded! Connecting to table DynamoDB:{}'.format(table_name))
128+
print('EICAR test file uploaded! Connecting to table DynamoDB:{}...'.format(table_name))
129129
table = boto3.resource('dynamodb').Table(table_name)
130130
eicar_sha256 = hashlib.sha256(EICAR_STRING.encode('UTF-8')).hexdigest()
131131
dynamo_record_found = False
132-
lambda_version = 0
133132

134133
for attempt in range(1, 11):
135134
time.sleep(5)
@@ -143,21 +142,22 @@ def live_test(self):
143142
KeyConditionExpression=Key('SHA256').eq(eicar_sha256),
144143
FilterExpression=Attr('S3Objects').contains(s3_identifier)
145144
).get('Items')
145+
146146
if items:
147147
print('\nSUCCESS: Expected DynamoDB entry for the EICAR file was found!\n')
148148
dynamo_record_found = True
149-
lambda_version = items[0]['LambdaVersion']
150149
pprint.pprint(items[0])
150+
151+
print('\nRemoving DynamoDB EICAR entry...')
152+
lambda_version = items[0]['LambdaVersion']
153+
table.delete_item(Key={'SHA256': eicar_sha256, 'LambdaVersion': lambda_version})
151154
break
152155
elif attempt == 10:
153156
print('\nFAIL: Expected DynamoDB entry for the EICAR file was *not* found!\n')
154157

155-
print('\nRemoving EICAR test file from S3...')
158+
print('Removing EICAR test file from S3...')
156159
bucket.delete_objects(Delete={'Objects': [{'Key': test_filename}]})
157160

158-
print('Removing DynamoDB EICAR entry...')
159-
table.delete_item(Key={'SHA256': eicar_sha256, 'LambdaVersion': lambda_version})
160-
161161
if dynamo_record_found:
162162
print('\nLive test succeeded! Verify the alert was sent to your SNS subscription(s).')
163163
else:

0 commit comments

Comments
 (0)