def test_consent_not_given(self, internal_response, internal_request, consent_verify_endpoint_regex, consent_registration_endpoint_regex): consent_config = SATOSAConfig(self.satosa_config) consent_module = ConsentModule(consent_config, identity_callback) expected_ticket = "my_ticket" responses.add(responses.GET, consent_verify_endpoint_regex, status=401) responses.add(responses.GET, consent_registration_endpoint_regex, status=200, body=expected_ticket) context = Context() state = State() context.state = state consent_module.save_state(internal_request, state) resp = consent_module.manage_consent(context, internal_response) self.assert_redirect(resp, expected_ticket) self.assert_registstration_req(responses.calls[1].request, consent_config.CONSENT["sign_key"]) context = Context() context.state = state # Verify endpoint of consent service still gives 401 (no consent given) context, internal_response = consent_module._handle_consent_response(context) assert not internal_response.get_attributes()
def test_consent_not_given(self, internal_response, internal_request, consent_verify_endpoint_regex, consent_registration_endpoint_regex): consent_config = SATOSAConfig(self.satosa_config) consent_module = ConsentModule(consent_config, identity_callback) expected_ticket = "my_ticket" responses.add(responses.GET, consent_verify_endpoint_regex, status=401) responses.add(responses.GET, consent_registration_endpoint_regex, status=200, body=expected_ticket) context = Context() state = State() context.state = state consent_module.save_state(internal_request, state) resp = consent_module.manage_consent(context, internal_response) self.assert_redirect(resp, expected_ticket) self.assert_registstration_req(responses.calls[1].request, consent_config.CONSENT["sign_key"]) context = Context() context.state = state # Verify endpoint of consent service still gives 401 (no consent given) context, internal_response = consent_module._handle_consent_response( context) assert not internal_response.get_attributes()
def test_consent_full_flow(self, internal_response, internal_request, consent_verify_endpoint_regex, consent_registration_endpoint_regex): consent_config = SATOSAConfig(self.satosa_config) consent_module = ConsentModule(consent_config, identity_callback) expected_ticket = "my_ticket" context = Context() state = State() context.state = state consent_module.save_state(internal_request, state) with responses.RequestsMock() as rsps: rsps.add(responses.GET, consent_verify_endpoint_regex, status=401) rsps.add(responses.GET, consent_registration_endpoint_regex, status=200, body=expected_ticket) resp = consent_module.manage_consent(context, internal_response) self.assert_redirect(resp, expected_ticket) self.assert_registstration_req(rsps.calls[1].request, consent_config.CONSENT["sign_key"]) with responses.RequestsMock() as rsps: # Now consent has been given, consent service returns 200 OK rsps.add(responses.GET, consent_verify_endpoint_regex, status=200, body=json.dumps(FILTER)) context = Context() context.state = state context, internal_response = consent_module._handle_consent_response(context) assert internal_response.get_attributes()["displayName"] == ["Test"] assert internal_response.get_attributes()["co"] == ["example"] assert "sn" not in internal_response.get_attributes() # 'sn' should be filtered
def test_consent_full_flow(self, internal_response, internal_request, consent_verify_endpoint_regex, consent_registration_endpoint_regex): consent_config = SATOSAConfig(self.satosa_config) consent_module = ConsentModule(consent_config, identity_callback) expected_ticket = "my_ticket" context = Context() state = State() context.state = state consent_module.save_state(internal_request, state) with responses.RequestsMock() as rsps: rsps.add(responses.GET, consent_verify_endpoint_regex, status=401) rsps.add(responses.GET, consent_registration_endpoint_regex, status=200, body=expected_ticket) resp = consent_module.manage_consent(context, internal_response) self.assert_redirect(resp, expected_ticket) self.assert_registstration_req(rsps.calls[1].request, consent_config.CONSENT["sign_key"]) with responses.RequestsMock() as rsps: # Now consent has been given, consent service returns 200 OK rsps.add(responses.GET, consent_verify_endpoint_regex, status=200, body=json.dumps(FILTER)) context = Context() context.state = state context, internal_response = consent_module._handle_consent_response( context) assert internal_response.get_attributes()["displayName"] == ["Test"] assert internal_response.get_attributes()["co"] == ["example"] assert "sn" not in internal_response.get_attributes( ) # 'sn' should be filtered