Skip to content

Commit 67f52df

Browse files
committed
Retain no-nonce test case, and add mismatching nonce test case
1 parent 25bcbf0 commit 67f52df

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/test_e2e.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,11 @@ def _get_app_and_auth_code(self, **kwargs):
133133
scopes=self.config["scope"],
134134
**kwargs)
135135

136-
def test_auth_code(self):
136+
def _test_auth_code(self, auth_kwargs, token_kwargs):
137137
self.skipUnlessWithConfig(["client_id", "scope"])
138-
nonce = "foo"
139-
(self.app, ac, redirect_uri) = self._get_app_and_auth_code(nonce=nonce)
138+
(self.app, ac, redirect_uri) = self._get_app_and_auth_code(**auth_kwargs)
140139
result = self.app.acquire_token_by_authorization_code(
141-
ac, self.config["scope"], redirect_uri=redirect_uri, nonce=nonce)
140+
ac, self.config["scope"], redirect_uri=redirect_uri, **token_kwargs)
142141
logger.debug("%s.cache = %s",
143142
self.id(), json.dumps(self.app.token_cache._cache, indent=4))
144143
self.assertIn(
@@ -149,6 +148,18 @@ def test_auth_code(self):
149148
error_description=result.get("error_description")))
150149
self.assertCacheWorksForUser(result, self.config["scope"], username=None)
151150

151+
def test_auth_code(self):
152+
self._test_auth_code({}, {})
153+
154+
def test_auth_code_with_matching_nonce(self):
155+
self._test_auth_code({"nonce": "foo"}, {"nonce": "foo"})
156+
157+
def test_auth_code_with_mismatching_nonce(self):
158+
self.skipUnlessWithConfig(["client_id", "scope"])
159+
(self.app, ac, redirect_uri) = self._get_app_and_auth_code(nonce="foo")
160+
with self.assertRaises(ValueError):
161+
self.app.acquire_token_by_authorization_code(
162+
ac, self.config["scope"], redirect_uri=redirect_uri, nonce="bar")
152163

153164
def test_ssh_cert(self):
154165
self.skipUnlessWithConfig(["client_id", "scope"])

0 commit comments

Comments
 (0)