def test_verify_signature(self) -> None: """Test the verify_signature method.""" vm_id = feconf.DEFAULT_VM_ID message = 'test message' expected_signature = ( '9c2f9f607c0eefc2b8ba153bad9331843a6efc71c82e690f5f0341bbc38b7fa7') invalid_signature = 'invalid signature' invalid_vm_id = 'invalid vm_id' oppia_ml_auth_info = classifier_domain.OppiaMLAuthInfo( message.encode('utf-8'), vm_id, expected_signature) self.assertTrue( classifier_services.verify_signature(oppia_ml_auth_info)) # Check if an invalid signature causes verify_signature to fail. oppia_ml_auth_info = classifier_domain.OppiaMLAuthInfo( message.encode('utf-8'), vm_id, invalid_signature) self.assertFalse( classifier_services.verify_signature(oppia_ml_auth_info)) # Check if an invalid vm_id causes verify_signature to fail. oppia_ml_auth_info = classifier_domain.OppiaMLAuthInfo( message.encode('utf-8'), invalid_vm_id, expected_signature) self.assertFalse( classifier_services.verify_signature(oppia_ml_auth_info))
def extract_request_message_vm_id_and_signature(self): """Returns message, vm_id and signature retrieved from incoming request. Returns: tuple(str). Message at index 0, vm_id at index 1 and signature at index 2. """ signature = self.normalized_payload.get('signature') vm_id = self.normalized_payload.get('vm_id') message = self.normalized_payload.get('message') return classifier_domain.OppiaMLAuthInfo(message, vm_id, signature)
def extract_request_message_vm_id_and_signature(self): """Returns message, vm_id and signature retrieved from incoming request. Returns: tuple(str). Message at index 0, vm_id at index 1 and signature at index 2. """ payload_proto = ( training_job_response_payload_pb2.TrainingJobResponsePayload()) payload_proto.ParseFromString(self.request.body) signature = payload_proto.signature vm_id = payload_proto.vm_id return classifier_domain.OppiaMLAuthInfo( payload_proto.job_result.SerializeToString(), vm_id, signature)
def setUp(self) -> None: super(OppiaMLAuthInfoDomainTests, self).setUp() self.oppia_ml_auth_info = classifier_domain.OppiaMLAuthInfo( 'hello', 'world', '!')