-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Peter Slump
committed
Mar 3, 2018
1 parent
75fe8d2
commit d177d53
Showing
10 changed files
with
180 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import mock | ||
|
||
from unittest import TestCase | ||
|
||
from keycloak.admin import KeycloakAdmin | ||
from keycloak.realm import KeycloakRealm | ||
|
||
|
||
class KeycloakAdminRolesTestCase(TestCase): | ||
|
||
def setUp(self): | ||
self.realm = mock.MagicMock(spec_set=KeycloakRealm) | ||
self.admin = KeycloakAdmin(realm=self.realm) | ||
self.admin.set_token('some-token') | ||
|
||
def test_create(self): | ||
self.admin.realms.by_name('realm-name').clients.by_id('#123').roles.\ | ||
create( | ||
name='my-role-name', | ||
description='my-description', | ||
id='my-id', | ||
client_role='my-client-role', | ||
composite=False, | ||
composites='my-composites', | ||
container_id='my-container-id', | ||
scope_param_required=True | ||
) | ||
self.realm.client.get_full_url.assert_called_once_with( | ||
'/auth/admin/realms/realm-name/clients/#123/roles' | ||
) | ||
self.realm.client.post.assert_called_once_with( | ||
url=self.realm.client.get_full_url.return_value, | ||
data='{' | ||
'"name": "my-role-name", ' | ||
'"description": "my-description", ' | ||
'"id": "my-id", ' | ||
'"clientRole": "my-client-role", ' | ||
'"composite": false, ' | ||
'"composites": "my-composites", ' | ||
'"containerId": "my-container-id", ' | ||
'"scopeParamRequired": true' | ||
'}', | ||
headers={ | ||
'Authorization': 'Bearer some-token', | ||
'Content-Type': 'application/json' | ||
} | ||
) | ||
|
||
def test_update(self): | ||
self.admin.realms.by_name('realm-name').clients.by_id( | ||
'#123').roles.by_name('role-name').update( | ||
name='my-role-name', | ||
description='my-description', | ||
id='my-id', | ||
client_role='my-client-role', | ||
composite=False, | ||
composites='my-composites', | ||
container_id='my-container-id', | ||
scope_param_required=True | ||
) | ||
self.realm.client.get_full_url.assert_called_once_with( | ||
'/auth/admin/realms/realm-name/clients/#123/roles/role-name' | ||
) | ||
self.realm.client.put.assert_called_once_with( | ||
url=self.realm.client.get_full_url.return_value, | ||
data='{' | ||
'"name": "my-role-name", ' | ||
'"description": "my-description", ' | ||
'"id": "my-id", ' | ||
'"clientRole": "my-client-role", ' | ||
'"composite": false, ' | ||
'"composites": "my-composites", ' | ||
'"containerId": "my-container-id", ' | ||
'"scopeParamRequired": true' | ||
'}', | ||
headers={ | ||
'Authorization': 'Bearer some-token', | ||
'Content-Type': 'application/json' | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import mock | ||
|
||
from unittest import TestCase | ||
|
||
from keycloak.admin import KeycloakAdmin | ||
from keycloak.realm import KeycloakRealm | ||
|
||
|
||
class KeycloakAdminUsersTestCase(TestCase): | ||
|
||
def setUp(self): | ||
self.realm = mock.MagicMock(spec_set=KeycloakRealm) | ||
self.admin = KeycloakAdmin(realm=self.realm) | ||
self.admin.set_token('some-token') | ||
|
||
def test_create(self): | ||
self.admin.realms.by_name('realm-name').users.create( | ||
username='my-username', | ||
credentials={'some': 'value'}, | ||
first_name='my-first-name', | ||
last_name='my-last-name', | ||
email='my-email', | ||
enabled=True | ||
) | ||
self.realm.client.get_full_url.assert_called_once_with( | ||
'/auth/admin/realms/realm-name/users' | ||
) | ||
self.realm.client.post.assert_called_once_with( | ||
url=self.realm.client.get_full_url.return_value, | ||
data='{"username": "my-username", ' | ||
'"credentials": [{"some": "value"}], ' | ||
'"firstName": "my-first-name", ' | ||
'"lastName": "my-last-name", ' | ||
'"email": "my-email", ' | ||
'"enabled": true}', | ||
headers={ | ||
'Authorization': 'Bearer some-token', | ||
'Content-Type': 'application/json' | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import mock | ||
|
||
from unittest import TestCase | ||
|
||
from keycloak.admin import KeycloakAdmin | ||
from keycloak.admin.realm import Realms | ||
from keycloak.realm import KeycloakRealm | ||
|
||
|
||
class KeycloakAdminTestCase(TestCase): | ||
|
||
def setUp(self): | ||
self.realm = mock.MagicMock(spec_set=KeycloakRealm) | ||
self.admin = KeycloakAdmin(realm=self.realm) | ||
|
||
def test_realm(self): | ||
|
||
realm = self.admin.realms | ||
self.assertIsInstance(realm, Realms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import mock | ||
|
||
from unittest import TestCase | ||
|
||
from keycloak.authz import KeycloakAuthz | ||
from keycloak.realm import KeycloakRealm | ||
|
||
|
||
class KeycloakAuthzTestCase(TestCase): | ||
|
||
def setUp(self): | ||
self.realm = mock.MagicMock(spec_set=KeycloakRealm) | ||
self.realm.realm_name = 'realm-name' | ||
self.client_id = 'client-id' | ||
|
||
self.authz = KeycloakAuthz(realm=self.realm, client_id=self.client_id) | ||
|
||
def test_entitlement(self): | ||
result = self.authz.entitlement(token='some-token') | ||
|
||
self.realm.client.get_full_url.assert_called_once_with( | ||
'auth/realms/realm-name/authz/entitlement/client-id' | ||
) | ||
self.realm.client.get.assert_called_once_with( | ||
self.realm.client.get_full_url.return_value, | ||
headers={ | ||
'Authorization': 'Bearer some-token' | ||
} | ||
) | ||
self.assertEqual(result, self.realm.client.get.return_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters