Sfoglia il codice sorgente

Add test for jitsi-meet feature

Guénaël Muller 6 anni fa
parent
commit
18cc28b79d
1 ha cambiato i file con 78 aggiunte e 0 eliminazioni
  1. 78 0
      tracim/tracim/tests/library/test_jitsi_meet.py

+ 78 - 0
tracim/tracim/tests/library/test_jitsi_meet.py Vedi File

@@ -0,0 +1,78 @@
1
+import datetime
2
+
3
+import jwt
4
+from nose.tools import raises
5
+
6
+from tracim.lib.jitsi_meet.jitsi_meet import JitsiTokenConfig
7
+from tracim.lib.jitsi_meet.jitsi_meet import JitsiMeetRoom
8
+from tracim.lib.jitsi_meet.jitsi_meet import NoTokenConfigError
9
+
10
+
11
+class TestJitsiMeetRoom(object):
12
+
13
+    TOKEN_CONFIG = JitsiTokenConfig(
14
+        app_id='test',
15
+        secret='secret',
16
+        alg='HS256',
17
+        duration=60,
18
+    )
19
+    ROOM = 'room'
20
+    DOMAIN = 'tracim'
21
+
22
+    def test_unit__generate_token(self) -> None:
23
+
24
+        jmr = JitsiMeetRoom(
25
+            domain=self.DOMAIN,
26
+            room=self.ROOM,
27
+            token_config=self.TOKEN_CONFIG,
28
+        )
29
+        str_token = jmr.generate_token()
30
+        decoded_token = jwt.decode(str_token,
31
+                                   key=self.TOKEN_CONFIG.secret,
32
+                                   algorithm=self.TOKEN_CONFIG.alg,
33
+                                   audience='*',
34
+                                   issuer=self.TOKEN_CONFIG.app_id,
35
+                                   )
36
+        assert decoded_token.get('room') == self.ROOM
37
+        assert decoded_token.get('iat')
38
+        assert decoded_token.get('iat') == decoded_token.get('nbf')
39
+        assert decoded_token.get('exp') == decoded_token.get('iat') + self.TOKEN_CONFIG.duration  # nopep8
40
+
41
+    @raises(NoTokenConfigError)
42
+    def test_unit__generate_token__no_token(self) -> None:
43
+        jmr = JitsiMeetRoom(
44
+            domain=self.DOMAIN,
45
+            room=self.ROOM,
46
+            token_config=None,
47
+        )
48
+        jmr.generate_token()
49
+
50
+    def test_unit__generate_url_token(self) -> None:
51
+        jmr = JitsiMeetRoom(
52
+            domain=self.DOMAIN,
53
+            room=self.ROOM,
54
+            token_config=self.TOKEN_CONFIG,
55
+        )
56
+
57
+        def generate_token():
58
+            return 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTYyNzA3NzksImlzcyI6InRlc3QiLCJhdWQiOiIqIiwibmJmIjoxNTE2MjcwNzE5LCJyb29tIjoicm9vbSIsImlhdCI6MTUxNjI3MDcxOX0.zqFBUcPGjlCfXTjuFP7brqalY8TKlgcg6DUE72KhCx0'  # nopep8
59
+
60
+        jmr.generate_token = generate_token
61
+        url = jmr.generate_url()
62
+        assert url == 'https://{domain}/{room}?jwt={token}'.format(
63
+            domain=self.DOMAIN,
64
+            room=self.ROOM,
65
+            token=generate_token()
66
+        )
67
+
68
+    def test_unit__generate_url_no_token(self) -> None:
69
+        jmr = JitsiMeetRoom(
70
+            domain=self.DOMAIN,
71
+            room=self.ROOM,
72
+            token_config=None,
73
+        )
74
+        url = jmr.generate_url()
75
+        assert url == 'https://{domain}/{room}'.format(
76
+            domain=self.DOMAIN,
77
+            room=self.ROOM,
78
+        )