2
2
import datetime
3
3
import hashlib
4
4
import json
5
- import re
6
5
from urllib .parse import parse_qs , urlparse
7
6
8
7
import pytest
32
31
RefreshToken = get_refresh_token_model ()
33
32
UserModel = get_user_model ()
34
33
35
- URI_OOB = "urn:ietf:wg:oauth:2.0:oob"
36
- URI_OOB_AUTO = "urn:ietf:wg:oauth:2.0:oob:auto"
37
34
CLEARTEXT_SECRET = "1234567890abcdefghijklmnopqrstuvwxyz"
38
35
39
36
@@ -56,7 +53,6 @@ def setUp(self):
56
53
name = "Test Application" ,
57
54
redirect_uris = (
58
55
"http://localhost http://example.com http://example.org custom-scheme://example.com"
59
- " " + URI_OOB + " " + URI_OOB_AUTO
60
56
),
61
57
user = self .dev_user ,
62
58
client_type = Application .CLIENT_CONFIDENTIAL ,
@@ -1532,92 +1528,6 @@ def test_code_exchange_succeed_when_redirect_uri_match_with_multiple_query_param
1532
1528
self .assertEqual (content ["scope" ], "read write" )
1533
1529
self .assertEqual (content ["expires_in" ], self .oauth2_settings .ACCESS_TOKEN_EXPIRE_SECONDS )
1534
1530
1535
- def test_oob_as_html (self ):
1536
- """
1537
- Test out-of-band authentication.
1538
- """
1539
- self .client .login (username = "test_user" , password = "123456" )
1540
-
1541
- authcode_data = {
1542
- "client_id" : self .application .client_id ,
1543
- "state" : "random_state_string" ,
1544
- "scope" : "read write" ,
1545
- "redirect_uri" : URI_OOB ,
1546
- "response_type" : "code" ,
1547
- "allow" : True ,
1548
- }
1549
-
1550
- response = self .client .post (reverse ("oauth2_provider:authorize" ), data = authcode_data )
1551
- self .assertEqual (response .status_code , 200 )
1552
- self .assertRegex (response ["Content-Type" ], r"^text/html" )
1553
-
1554
- content = response .content .decode ("utf-8" )
1555
-
1556
- # "A lot of applications, for legacy reasons, use this and regex
1557
- # to extract the token, risking summoning zalgo in the process."
1558
- # -- https://github.com/jazzband/django-oauth-toolkit/issues/235
1559
-
1560
- matches = re .search (r".*<code>([^<>]*)</code>" , content )
1561
- self .assertIsNotNone (matches , msg = "OOB response contains code inside <code> tag" )
1562
- self .assertEqual (len (matches .groups ()), 1 , msg = "OOB response contains multiple <code> tags" )
1563
- authorization_code = matches .groups ()[0 ]
1564
-
1565
- token_request_data = {
1566
- "grant_type" : "authorization_code" ,
1567
- "code" : authorization_code ,
1568
- "redirect_uri" : URI_OOB ,
1569
- "client_id" : self .application .client_id ,
1570
- "client_secret" : CLEARTEXT_SECRET ,
1571
- }
1572
-
1573
- response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data )
1574
- self .assertEqual (response .status_code , 200 )
1575
-
1576
- content = json .loads (response .content .decode ("utf-8" ))
1577
- self .assertEqual (content ["token_type" ], "Bearer" )
1578
- self .assertEqual (content ["scope" ], "read write" )
1579
- self .assertEqual (content ["expires_in" ], self .oauth2_settings .ACCESS_TOKEN_EXPIRE_SECONDS )
1580
-
1581
- def test_oob_as_json (self ):
1582
- """
1583
- Test out-of-band authentication, with a JSON response.
1584
- """
1585
- self .client .login (username = "test_user" , password = "123456" )
1586
-
1587
- authcode_data = {
1588
- "client_id" : self .application .client_id ,
1589
- "state" : "random_state_string" ,
1590
- "scope" : "read write" ,
1591
- "redirect_uri" : URI_OOB_AUTO ,
1592
- "response_type" : "code" ,
1593
- "allow" : True ,
1594
- }
1595
-
1596
- response = self .client .post (reverse ("oauth2_provider:authorize" ), data = authcode_data )
1597
- self .assertEqual (response .status_code , 200 )
1598
- self .assertRegex (response ["Content-Type" ], "^application/json" )
1599
-
1600
- parsed_response = json .loads (response .content .decode ("utf-8" ))
1601
-
1602
- self .assertIn ("access_token" , parsed_response )
1603
- authorization_code = parsed_response ["access_token" ]
1604
-
1605
- token_request_data = {
1606
- "grant_type" : "authorization_code" ,
1607
- "code" : authorization_code ,
1608
- "redirect_uri" : URI_OOB_AUTO ,
1609
- "client_id" : self .application .client_id ,
1610
- "client_secret" : CLEARTEXT_SECRET ,
1611
- }
1612
-
1613
- response = self .client .post (reverse ("oauth2_provider:token" ), data = token_request_data )
1614
- self .assertEqual (response .status_code , 200 )
1615
-
1616
- content = json .loads (response .content .decode ("utf-8" ))
1617
- self .assertEqual (content ["token_type" ], "Bearer" )
1618
- self .assertEqual (content ["scope" ], "read write" )
1619
- self .assertEqual (content ["expires_in" ], self .oauth2_settings .ACCESS_TOKEN_EXPIRE_SECONDS )
1620
-
1621
1531
1622
1532
@pytest .mark .oauth2_settings (presets .OIDC_SETTINGS_RW )
1623
1533
class TestOIDCAuthorizationCodeTokenView (BaseAuthorizationCodeTokenView ):
0 commit comments