Beispiel #1
0
 def test_get_session_sid_None(self):
     ''' get_session should return the first session if sid is None '''
     username = '******'
     privkey = crypto.generate_rsa_key()
     sessionIndex.sessions = []
     s1 = session.KomlogSession(username, privkey)
     self.assertTrue(s1 in sessionIndex.sessions)
     s2 = session.KomlogSession(username, privkey)
     self.assertTrue(s2 in sessionIndex.sessions)
     ss = sessionIndex.get_session()
     self.assertEqual(s1,ss)
Beispiel #2
0
 def test_get_session_sid(self):
     ''' get_session should return the session with sid '''
     username = '******'
     privkey = crypto.generate_rsa_key()
     s1 = session.KomlogSession(username, privkey)
     self.assertTrue(s1 in sessionIndex.sessions)
     s2 = session.KomlogSession(username, privkey)
     self.assertTrue(s2 in sessionIndex.sessions)
     ss = sessionIndex.get_session(s1.sid)
     self.assertEqual(ss,s1)
     ss = sessionIndex.get_session(s2.sid)
     self.assertEqual(ss,s2)
Beispiel #3
0
 def test_komlogsession_creation_failure_invalid_privkey(self):
     ''' creating a KomlogSession object should fail if privkey is invalid '''
     username = '******'
     privkey = 'privkey'
     with self.assertRaises(exceptions.BadParametersException) as cm:
         session.KomlogSession(username=username, privkey=privkey)
     self.assertEqual(cm.exception.msg, 'Invalid private key')
Beispiel #4
0
 def test_komlogsession_creation_username_modification_not_allowed(self):
     ''' username cannot be modified on la KomlogSession object '''
     username = '******'
     privkey = crypto.generate_rsa_key()
     s = session.KomlogSession(username=username, privkey=privkey)
     with self.assertRaises(exceptions.BadParametersException) as cm:
         s.username = '******'
     self.assertEqual(cm.exception.msg, 'username modification not allowed')
Beispiel #5
0
 def test_komlogsession_creation_failure_invalid_username(self):
     ''' creating a KomlogSession object should fail if user is invalid '''
     username = '******'
     privkey = crypto.generate_rsa_key()
     with self.assertRaises(exceptions.BadParametersException) as cm:
         session.KomlogSession(username=username, privkey=privkey)
     self.assertEqual(cm.exception.msg,
                      'Invalid username {}'.format(str(username)))
Beispiel #6
0
 def test_unregister_session(self):
     ''' unregistering a session should add the session to the session list '''
     username = '******'
     privkey = crypto.generate_rsa_key()
     s = session.KomlogSession(username, privkey)
     self.assertTrue(s in sessionIndex.sessions)
     self.assertTrue(sessionIndex.unregister_session(s.sid))
     self.assertFalse(s in sessionIndex.sessions)
Beispiel #7
0
 def test_register_session_only_add_the_session_once(self):
     ''' creating a session should add it to the sessionIndex automatically '''
     username = '******'
     privkey = crypto.generate_rsa_key()
     sessionIndex.sessions = []
     s = session.KomlogSession(username, privkey)
     self.assertTrue(s in sessionIndex.sessions)
     self.assertEqual(len(sessionIndex.sessions),1)
     self.assertTrue(sessionIndex.register_session(s))
     self.assertTrue(s in sessionIndex.sessions)
     self.assertEqual(len(sessionIndex.sessions),1)
Beispiel #8
0
def initialize_komlog_session():
    privkey = crypto.get_private_key()
    username = config.config.username
    return session.KomlogSession(username=username, privkey=privkey)
Beispiel #9
0
 def test_komlogsession_creation_success(self):
     username = '******'
     privkey = crypto.generate_rsa_key()
     s = session.KomlogSession(username=username, privkey=privkey)
     s2 = sessionIndex.get_session(sid=s.sid)
     self.assertEqual(s, s2)
Beispiel #10
0
 def test_register_session_automatically_when_session_is_created(self):
     ''' creating a session should add it to the sessionIndex automatically '''
     username = '******'
     privkey = crypto.generate_rsa_key()
     s = session.KomlogSession(username, privkey)
     self.assertTrue(s in sessionIndex.sessions)