Example #1
0
 def test_not_secured(self):
     from ramses import auth
     raml_data = Mock(secured_by=[None])
     config = Mock()
     auth.setup_auth_policies(config, raml_data)
     assert not config.set_authentication_policy.called
     assert not config.set_authorization_policy.called
Example #2
0
 def test_not_secured(self):
     from ramses import auth
     raml_data = Mock(secured_by=[None])
     config = Mock()
     auth.setup_auth_policies(config, raml_data)
     assert not config.set_authentication_policy.called
     assert not config.set_authorization_policy.called
Example #3
0
 def test_not_defined_security_scheme(self):
     from ramses import auth
     raml_data = Mock(securedBy=['zoo'], securitySchemes={'foo': 'bar'})
     with pytest.raises(ValueError) as ex:
         auth.setup_auth_policies('asd', raml_data)
     expected = 'Not defined security scheme used in `securedBy`: zoo'
     assert expected == str(ex.value)
Example #4
0
 def test_not_supported_scheme_type(self):
     from ramses import auth
     scheme = Mock(type='asd123')
     scheme.name = 'foo'
     raml_data = Mock(secured_by=['foo'], security_schemes=[scheme])
     with pytest.raises(ValueError) as ex:
         auth.setup_auth_policies(None, raml_data)
     expected = 'Unsupported security scheme type: asd123'
     assert expected == str(ex.value)
Example #5
0
 def test_not_defined_security_scheme(self):
     from ramses import auth
     scheme = Mock()
     scheme.name = 'foo'
     raml_data = Mock(secured_by=['zoo'], security_schemes=[scheme])
     with pytest.raises(ValueError) as ex:
         auth.setup_auth_policies('asd', raml_data)
     expected = 'Undefined security scheme used in `secured_by`: zoo'
     assert expected == str(ex.value)
Example #6
0
 def test_not_supported_scheme_type(self):
     from ramses import auth
     scheme = Mock(type='asd123')
     scheme.name = 'foo'
     raml_data = Mock(secured_by=['foo'], security_schemes=[scheme])
     with pytest.raises(ValueError) as ex:
         auth.setup_auth_policies(None, raml_data)
     expected = 'Unsupported security scheme type: asd123'
     assert expected == str(ex.value)
Example #7
0
 def test_not_defined_security_scheme(self):
     from ramses import auth
     scheme = Mock()
     scheme.name = 'foo'
     raml_data = Mock(secured_by=['zoo'], security_schemes=[scheme])
     with pytest.raises(ValueError) as ex:
         auth.setup_auth_policies('asd', raml_data)
     expected = 'Undefined security scheme used in `secured_by`: zoo'
     assert expected == str(ex.value)
Example #8
0
 def test_not_supported_scheme_type(self):
     from ramses import auth
     raml_data = Mock(
         securedBy=['foo'],
         securitySchemes={'foo': Mock(type='asd123')}
     )
     with pytest.raises(ValueError) as ex:
         auth.setup_auth_policies(None, raml_data)
     expected = 'Not supported security scheme type: asd123'
     assert expected == str(ex.value)
Example #9
0
 def test_policies_calls(self, mock_acl):
     from ramses import auth
     scheme = Mock(type='mytype', settings={'name': 'user1'})
     scheme.name = 'foo'
     raml_data = Mock(secured_by=['foo'], security_schemes=[scheme])
     config = Mock()
     mock_setup = Mock()
     with patch.dict(auth.AUTHENTICATION_POLICIES, {'mytype': mock_setup}):
         auth.setup_auth_policies(config, raml_data)
     mock_setup.assert_called_once_with(config, {'name': 'user1'})
     config.set_authentication_policy.assert_called_once_with(mock_setup())
     mock_acl.assert_called_once_with()
     config.set_authorization_policy.assert_called_once_with(mock_acl())
Example #10
0
 def test_policies_calls(self, mock_acl):
     from ramses import auth
     scheme = Mock(type='mytype', settings={'name': 'user1'})
     scheme.name = 'foo'
     raml_data = Mock(secured_by=['foo'], security_schemes=[scheme])
     config = Mock()
     mock_setup = Mock()
     with patch.dict(auth.AUTHENTICATION_POLICIES, {'mytype': mock_setup}):
         auth.setup_auth_policies(config, raml_data)
     mock_setup.assert_called_once_with(config, {'name': 'user1'})
     config.set_authentication_policy.assert_called_once_with(
         mock_setup())
     mock_acl.assert_called_once_with()
     config.set_authorization_policy.assert_called_once_with(
         mock_acl())