|
1 | 1 | import json |
2 | 2 | import base64 |
| 3 | +from datetime import date, timedelta |
| 4 | + |
3 | 5 | from django.conf import settings |
4 | 6 | from django.http import HttpRequest |
5 | 7 | from django.urls import reverse |
@@ -465,6 +467,43 @@ def test_get_tokens_success(self): |
465 | 467 | ] |
466 | 468 | self.assertEqual(result, expected) |
467 | 469 |
|
| 470 | + # Check tokens endpoint doesn't return expired |
| 471 | + application2 = self._create_application( |
| 472 | + "an expired app", |
| 473 | + grant_type=Application.GRANT_AUTHORIZATION_CODE, |
| 474 | + redirect_uris="http://example.it", |
| 475 | + user=anna |
| 476 | + ) |
| 477 | + DataAccessGrant.objects.update_or_create( |
| 478 | + beneficiary=anna, application=application2, expiration_date=date.today() - timedelta(days=1) |
| 479 | + ) |
| 480 | + response = self.client.get( |
| 481 | + "/v1/o/tokens/", |
| 482 | + headers={ |
| 483 | + "authorization": self._create_authorization_header( |
| 484 | + application.client_id, application.client_secret_plain |
| 485 | + ), |
| 486 | + "x-authentication": self._create_authentication_header(self.test_uuid), |
| 487 | + }, |
| 488 | + ) |
| 489 | + self.assertEqual(response.status_code, 200) |
| 490 | + result = response.json() |
| 491 | + expected = [ |
| 492 | + { |
| 493 | + "id": result[0]["id"], |
| 494 | + "user": anna.id, |
| 495 | + "application": { |
| 496 | + "id": application.id, |
| 497 | + "name": "an app", |
| 498 | + "logo_uri": "", |
| 499 | + "tos_uri": "", |
| 500 | + "policy_uri": "", |
| 501 | + "contacts": "", |
| 502 | + }, |
| 503 | + } |
| 504 | + ] |
| 505 | + self.assertEqual(result, expected) |
| 506 | + |
468 | 507 | def test_get_tokens_on_inactive_app(self): |
469 | 508 | anna = self._create_user(self.test_username, "123456") |
470 | 509 | # create a couple of capabilities |
|
0 commit comments