-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add management command to check service configuration
- Loading branch information
Showing
3 changed files
with
91 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from mama_cas.services import get_callbacks | ||
from mama_cas.services import get_logout_url | ||
from mama_cas.services import logout_allowed | ||
from mama_cas.services import proxy_allowed | ||
from mama_cas.services import proxy_callback_allowed | ||
from mama_cas.services import service_allowed | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Check validity and configuration of a service identifier' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'service', | ||
help='Service identifier to check' | ||
) | ||
parser.add_argument( | ||
'pgturl', nargs='?', | ||
help='Optional pgtUrl to test proxy callback identifier' | ||
) | ||
|
||
def handle(self, **options): | ||
service = options['service'] | ||
pgturl = options['pgturl'] | ||
if service_allowed(service): | ||
self.stdout.write('Valid Service: %s' % service) | ||
self.stdout.write('Proxy Allowed: %s' % proxy_allowed(service)) | ||
if pgturl: | ||
self.stdout.write('Proxy Callback Allowed: %s' % proxy_callback_allowed(service, pgturl)) | ||
self.stdout.write('Logout Allowed: %s' % logout_allowed(service)) | ||
self.stdout.write('Logout URL: %s' % get_logout_url(service)) | ||
self.stdout.write('Callbacks: %s' % get_callbacks(service)) | ||
else: | ||
self.stdout.write(self.style.ERROR('Invalid Service: %s' % service)) |
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,55 @@ | ||
from django.core import management | ||
from django.test import TestCase | ||
from django.utils import six | ||
|
||
from .factories import ProxyGrantingTicketFactory | ||
from .factories import ProxyTicketFactory | ||
from .factories import ServiceTicketFactory | ||
from mama_cas.models import ProxyGrantingTicket | ||
from mama_cas.models import ProxyTicket | ||
from mama_cas.models import ServiceTicket | ||
|
||
|
||
class ManagementCommandTests(TestCase): | ||
""" | ||
Test management commands that operate on tickets. | ||
""" | ||
def test_cleanupcas_management_command(self): | ||
""" | ||
The ``cleanupcas`` management command should delete tickets | ||
that are expired or consumed. | ||
""" | ||
st = ServiceTicketFactory(consume=True) | ||
pgt = ProxyGrantingTicketFactory(expire=True, granted_by_st=st) | ||
ProxyTicketFactory(consume=True, granted_by_pgt=pgt) | ||
management.call_command('cleanupcas') | ||
|
||
self.assertEqual(ServiceTicket.objects.count(), 0) | ||
self.assertEqual(ProxyGrantingTicket.objects.count(), 0) | ||
self.assertEqual(ProxyTicket.objects.count(), 0) | ||
|
||
def test_cleanupcas_management_command_chain(self): | ||
""" | ||
The ``cleanupcas`` management command should delete chains of | ||
invalid tickets. | ||
""" | ||
st = ServiceTicketFactory(consume=True) | ||
pgt = ProxyGrantingTicketFactory(expire=True, granted_by_st=st) | ||
pt = ProxyTicketFactory(consume=True, granted_by_pgt=pgt) | ||
pgt2 = ProxyGrantingTicketFactory(expire=True, granted_by_st=None, granted_by_pt=pt) | ||
ProxyTicketFactory(consume=True, granted_by_pgt=pgt2) | ||
management.call_command('cleanupcas') | ||
|
||
self.assertEqual(ServiceTicket.objects.count(), 0) | ||
self.assertEqual(ProxyGrantingTicket.objects.count(), 0) | ||
self.assertEqual(ProxyTicket.objects.count(), 0) | ||
|
||
def test_checkservice_management_command(self): | ||
output = six.StringIO() | ||
management.call_command('checkservice', 'https://www.example.com', no_color=True, stdout=output) | ||
self.assertIn('Valid Service', output.getvalue()) | ||
|
||
def test_checkservice_management_command_invalid(self): | ||
output = six.StringIO() | ||
management.call_command('checkservice', 'https://example.org', no_color=True, stdout=output) | ||
self.assertIn('Invalid Service', output.getvalue()) |
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