def test_make_session(self): session = openid.make_session( { 'email': u'email', 'name': u'name', 'picture': u'picture', 'sub': u'user-id', }, expiration_sec=3600) self.assertEqual( ndb.Key(openid.AuthOpenIDUser, 'user-id', openid.AuthOpenIDSession, 1), session.key) self.assertEqual( { 'closed_ts': None, 'created_ts': datetime.datetime(2015, 1, 1, 1, 1, 1, 1), 'email': u'email', 'expiration_ts': datetime.datetime(2015, 1, 1, 2, 1, 1, 1), 'is_open': True, 'name': u'name', 'picture': u'picture', }, session.to_dict()) session_cookie = openid.make_session_cookie(session) self.assertEqual( 'AnsiX2kiOiIxNDIwMDc0MDYxMDAwIiwic3MiOiIxIiwic3ViIjoidXNlci1pZCJ93v490y1l' 'YLFkvz8f6fculiqLwhe28bKL9TxXobrQxFg', session_cookie)
def test_make_session(self): session = openid.make_session({ 'email': u'email', 'name': u'name', 'picture': u'picture', 'sub': u'user-id', }, expiration_sec=3600) self.assertEqual( ndb.Key(openid.AuthOpenIDUser, 'user-id', openid.AuthOpenIDSession, 1), session.key) self.assertEqual({ 'closed_ts': None, 'created_ts': datetime.datetime(2015, 1, 1, 1, 1, 1, 1), 'email': u'email', 'expiration_ts': datetime.datetime(2015, 1, 1, 2, 1, 1, 1), 'is_open': True, 'name': u'name', 'picture': u'picture', }, session.to_dict()) session_cookie = openid.make_session_cookie(session) self.assertEqual( 'AXsiX2kiOiIxNDIwMDc0MDYxMDAwIiwic3MiOiJcdTAwMDFcdTAwMDBcdTAwMDBcdTAwMDBc' 'dTAwMDBcdTAwMDBcdTAwMDBcdTAwMDAiLCJzdWIiOiJ1c2VyLWlkIn1rVeAKbNE4fNP12wu8' 'icMZ88LQqyP2oQ7s_Kab_SsZGQ', session_cookie)
def test_session_cookie_serialization(self): for i in xrange(1, 1024): session = openid.AuthOpenIDSession(id=i, parent=ndb.Key( openid.AuthOpenIDUser, 'blah')) cookie = openid.make_session_cookie(session) openid.SessionCookie.validate(cookie)
def test_get_open_session_ok(self): session = openid.make_session({ 'email': u'email', 'name': u'name', 'picture': u'picture', 'sub': u'user-id', }, expiration_sec=3600) session_cookie = openid.make_session_cookie(session) self.assertEqual(session, openid.get_open_session(session_cookie))
def test_session_close(self): session = openid.make_session({ 'email': u'email', 'name': u'name', 'picture': u'picture', 'sub': u'user-id', }, expiration_sec=3600) session_cookie = openid.make_session_cookie(session) openid.close_session(session_cookie) self.assertIsNone(openid.get_open_session(session_cookie))
def test_session_expiration(self): session = openid.make_session({ 'email': u'email', 'name': u'name', 'picture': u'picture', 'sub': u'user-id', }, expiration_sec=3600) session_cookie = openid.make_session_cookie(session) self.mock_now(datetime.datetime(2015, 1, 2, 1, 1, 1, 1)) self.assertIsNone(openid.get_open_session(session_cookie))
def test_get_open_session_bad_cookie(self): session = openid.make_session({ 'email': u'email', 'name': u'name', 'picture': u'picture', 'sub': u'user-id', }, expiration_sec=3600) session_cookie = openid.make_session_cookie(session) self.assertIsNone(openid.get_open_session(session_cookie+'blah')) self.assertIsNone(openid.get_open_session(None)) session.key.delete() self.assertIsNone(openid.get_open_session(session_cookie))
def test_make_session(self): session = openid.make_session({ 'email': u'email', 'name': u'name', 'picture': u'picture', 'sub': u'user-id', }, expiration_sec=3600) self.assertEqual( ndb.Key(openid.AuthOpenIDUser, 'user-id', openid.AuthOpenIDSession, 1), session.key) self.assertEqual({ 'closed_ts': None, 'created_ts': datetime.datetime(2015, 1, 1, 1, 1, 1, 1), 'email': u'email', 'expiration_ts': datetime.datetime(2015, 1, 1, 2, 1, 1, 1), 'is_open': True, 'name': u'name', 'picture': u'picture', }, session.to_dict()) session_cookie = openid.make_session_cookie(session) self.assertEqual( 'AnsiX2kiOiIxNDIwMDc0MDYxMDAwIiwic3MiOiIxIiwic3ViIjoidXNlci1pZCJ93v490y1l' 'YLFkvz8f6fculiqLwhe28bKL9TxXobrQxFg', session_cookie)
def test_session_cookie_serialization(self): for i in xrange(1, 1024): session = openid.AuthOpenIDSession( id=i, parent=ndb.Key(openid.AuthOpenIDUser, 'blah')) cookie = openid.make_session_cookie(session) openid.SessionCookie.validate(cookie)