Commits

Anonymous committed 4d0deb0

discovery json

Comments (0)

Files changed (5)

 export RP=rp.accounts.deb
 export OP_PORT=8004
 export RP_PORT=8005
+export OP_HOST=$OP:$OP_PORT
+export RP_HOST=$RP:$RP_PORT
+
 
 export ACCOUNTS_JS_OP=$OP
 export ACCOUNTS_JS_RP=$RP

src/accounts/fixtures/tests/op.local.openidserver.json

+[
+  {
+    "pk": 1, 
+    "model": "openid.openidserver", 
+    "fields": {
+      "x509_encryption_url": "", 
+      "request_object_algs_supported": "", 
+      "acrs_supported": "[]", 
+      "check_id_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/check_id", 
+      "x509_url": "", 
+      "issuer": "http://op.accounts.deb:8004", 
+      "server_id": "http://op.accounts.deb:8004", 
+      "token_endpoint_auth_types_supported": "[\"client_secret_basic\"]", 
+      "is_remote": false, 
+      "refresh_session_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/refresh_session", 
+      "token_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/token", 
+      "version": "3.0", 
+      "token_endpoint_auth_algs_supported": "[\"RS256\"]", 
+      "registration_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/registration", 
+      "jwk_encryption_url": "", 
+      "jwk_url": "", 
+      "scopes_supported": "[\"openid\"]", 
+      "id_token_algs_supported": "", 
+      "userinfo_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/userinfo", 
+      "userinfo_algs_supported": "", 
+      "user_id_types_supported": "[\"pairwise\",\"public\"]", 
+      "response_types_supported": "[\"code\",\"token\",\"id_token\",\"id_token token\",\"code token\",\"code id_token\",\"code id_token token\"]", 
+      "end_session_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/end_session", 
+      "authorization_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/request"
+    }
+  }
+]

src/accounts/fixtures/tests/rp.remote.openidserver.json

+[
+  {
+    "pk": 2, 
+    "model": "openid.openidserver", 
+    "fields": {
+      "x509_encryption_url": "", 
+      "request_object_algs_supported": "", 
+      "acrs_supported": "[]", 
+      "check_id_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/check_id", 
+      "x509_url": "", 
+      "issuer": "http://op.accounts.deb:8004", 
+      "server_id": "op.accounts.deb:8004", 
+      "token_endpoint_auth_types_supported": "[u'client_secret_basic']", 
+      "is_remote": true, 
+      "refresh_session_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/refresh_session", 
+      "token_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/token", 
+      "version": "3.0", 
+      "token_endpoint_auth_algs_supported": "[u'RS256']", 
+      "registration_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/registration", 
+      "jwk_encryption_url": "", 
+      "jwk_url": "", 
+      "scopes_supported": "[u'openid']", 
+      "id_token_algs_supported": "", 
+      "userinfo_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/userinfo", 
+      "userinfo_algs_supported": "", 
+      "user_id_types_supported": "[u'pairwise', u'public']", 
+      "response_types_supported": "[u'code', u'token', u'id_token', u'id_token token', u'code token', u'code id_token', u'code id_token token']", 
+      "end_session_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/end_session", 
+      "authorization_endpoint": "http://op.accounts.deb:8004/accounts/openid/op/request"
+    }
+  }
+]

src/accounts/openid/models.py

         '''
         dv = dict(
             [(f.name,getattr(self,f.name))
-                 for f in AbstractOpenIDDiscoveryResponse._meta.fields ]
+                 for f in OpenIDDiscovery._meta.fields ]
             )
         for k,v in dv.items():
             if re.search(r'^\[.*\]',v):

src/accounts/tests.py

 # -*- coding: utf-8 -*-
 
-import sys 
+import sys ,os
 if sys.version_info < (2,7):
     import unittest2 as unittest
 
         map(lambda m:m.save(), 
             serializers.deserialize('json',self.open_fixture(path,filename)) )        
 
-class RpTest(TestCast):
-    pass
+class OpenIDRpTest(BasicTest):
+    def setUp(self):
+   
+        #:OP:Local OP 
+        map(lambda m:m.save(),
+            serializers.deserialize('json',
+                self.open_fixture('fixtures/tests','op.local.openidserver.json'))
+            )
+
+    def test_discovery(self):
+        ''' python manage.py test accounts.OpenIDRpTest.test_discovery
+        '''
+        from django.test import Client
+        import json
+        from accounts.openid.models import OpenIDServer
+        server_id = os.environ['OP_HOST'] 
+        c=Client()
+        res=c.get('/.well-known/openid-configuration',{},
+                    HTTP_HOST=server_id )
+        op_conf = json.loads(res.content)
+        op_conf['server_id'] = server_id
+        rp_remote_op = OpenIDServer(**op_conf)
+        rp_remote_op.save()
+
+        self.assertEqual(OpenIDServer.objects.filter(is_remote = False).count(),1)  #: OP local
+        self.assertEqual(OpenIDServer.objects.filter(is_remote = True ).count(),1)  #: RP remote
+        
+        if os.path.isdir('.fixtures') == False:
+            os.makedirs('.fixtures') 
+        
+        serializers.serialize('json', 
+                            OpenIDServer.objects.filter(is_remote = False),
+                            stream=open('.fixtures/op.local.openidserver.json','w'),
+                            ensure_ascii=False,indent=2)
+    
+        serializers.serialize('json', 
+                            OpenIDServer.objects.filter(is_remote = True),
+                            stream=open('.fixtures/rp.remote.openidserver.json','w'),
+                            ensure_ascii=False,indent=2)