def test_validate_timestamp(self, mock_time): timestamp1 = 1577804700 mock_time.return_value = 1577804400 actual = FileControllerHelper.valid_timestamp(timestamp1) self.assertTrue(actual) timestamp1 = 1577804800 mock_time.return_value = 1577804400 actual = FileControllerHelper.valid_timestamp(timestamp1) self.assertFalse(actual)
def list(self, event: Dict) -> Dict[str, Union[int, Dict[str, str], str]]: try: is_local = self.__env_vars.stage == 'local' valid_timestamp = True valid_signature = True if not is_local: headers: SlashCommandHeaders = FileControllerHelper.get_command_header(event) raw_body = FileControllerHelper.get_raw_body(event) valid_signature = FileControllerHelper.valid_signature( headers, raw_body, self.__env_vars.slack_signing_secret) valid_timestamp = FileControllerHelper.valid_timestamp(headers.slack_request_timestamp) if not valid_timestamp: raise InvalidTimestampException(event['headers']) if not valid_signature: raise InvalidSignatureException(event['headers']) body: SlashCommandBody = FileControllerHelper.get_command_body(event) FileControllerHelper.validate_body(body) parsed_text: ParsedText = FileControllerHelper.parse_text(body.text) input_data: FileListInput = FileListInput( token=self.__env_vars.token, date_from=parsed_text.date_from, date_to=parsed_text.date_to, channel=body.channel_id if parsed_text.all_channels else None, user=body.user_id if parsed_text.all_users else None, ) output: FileListOutput = self.__usecase.handle(input_data) return self.__presenter.complete(output, None) except Exception as ex: return self.__presenter.complete(FileListOutput([]), ex)