Skip to content

Commit 0c0b926

Browse files
committed
added tests for approval_prompt
1 parent 9dc45de commit 0c0b926

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

oauth2_provider/tests/test_authorization_code.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import base64
44
import json
5+
import datetime
56

67
from django.test import TestCase, RequestFactory
78
from django.core.urlresolvers import reverse
89
from django.utils import timezone
910

1011
from ..compat import urlparse, parse_qs, urlencode, get_user_model
11-
from ..models import get_application_model, Grant
12+
from ..models import get_application_model, Grant, AccessToken
1213
from ..settings import oauth2_settings
1314
from ..views import ProtectedResourceView
1415

@@ -91,6 +92,32 @@ def test_pre_auth_valid_client(self):
9192
self.assertEqual(form['scopes'].value(), "read write")
9293
self.assertEqual(form['client_id'].value(), self.application.client_id)
9394

95+
def test_pre_auth_approval_prompt(self):
96+
"""
97+
98+
"""
99+
tok = AccessToken.objects.create(user=self.test_user, token='1234567890',
100+
application=self.application,
101+
expires=timezone.now()+datetime.timedelta(days=1),
102+
scope='read write')
103+
self.client.login(username="test_user", password="123456")
104+
query_string = urlencode({
105+
'client_id': self.application.client_id,
106+
'response_type': 'code',
107+
'state': 'random_state_string',
108+
'scope': 'read write',
109+
'redirect_uri': 'http://example.it',
110+
'approval_prompt': 'auto',
111+
})
112+
url = "{url}?{qs}".format(url=reverse('oauth2_provider:authorize'), qs=query_string)
113+
response = self.client.get(url)
114+
self.assertEqual(response.status_code, 302)
115+
# user already authorized the application, but with different scopes: prompt them.
116+
tok.scope = 'read'
117+
tok.save()
118+
response = self.client.get(url)
119+
self.assertEqual(response.status_code, 200)
120+
94121
def test_pre_auth_default_redirect(self):
95122
"""
96123
Test for default redirect uri if omitted from query string with response_type: code

0 commit comments

Comments
 (0)