|
6 | 6 |
|
7 | 7 | package com.opentok.test;
|
8 | 8 |
|
| 9 | +import java.io.UnsupportedEncodingException; |
| 10 | +import java.security.InvalidKeyException; |
| 11 | +import java.security.NoSuchAlgorithmException; |
| 12 | +import java.security.SignatureException; |
9 | 13 | import java.util.Date;
|
10 | 14 | import java.util.HashMap;
|
11 | 15 | import java.util.Map;
|
12 | 16 | import java.util.Map.Entry;
|
13 | 17 |
|
| 18 | +import com.opentok.test.Helpers; |
| 19 | + |
14 | 20 | import com.opentok.api.OpenTok;
|
15 | 21 | import com.opentok.api.Session;
|
16 | 22 | import com.opentok.api.constants.Version;
|
@@ -153,28 +159,27 @@ public void testCreateBadSession() throws OpenTokException {
|
153 | 159 |
|
154 | 160 | // TODO: test session creation conditions that result in errors
|
155 | 161 |
|
156 |
| -// @Test |
157 |
| -// public void testRoleDefault() throws OpenTokException { |
158 |
| -// Session s= sdk.createSession(); |
159 |
| -// String t = s.generateToken(); |
160 |
| -// TokBoxXML xml = get_token_info(t); |
161 |
| -// |
162 |
| -// String expectedRole = "publisher"; |
163 |
| -// String actualRole = xml.getElementValue("role", "token").trim(); |
164 |
| -// Assert.assertEquals("Java SDK tests: role default not default (publisher)", expectedRole, actualRole); |
165 |
| -// |
166 |
| -// // Permissions are set as an empty node in the xml |
167 |
| -// // Verify that the expected permission node is there |
168 |
| -// // Verify nodes for permissions not granted to the role are not there |
169 |
| -// Assert.assertTrue("Java SDK tests: default role does not have subscriber permissions", xml.hasElement("subscribe", "permissions")); |
170 |
| -// Assert.assertTrue("Java SDK tests: default role does not have publisher permissions", xml.hasElement("publish", "permissions")); |
171 |
| -// Assert.assertTrue("Java SDK tests: default role does not have signal permissions", xml.hasElement("signal", "permissions")); |
172 |
| -// Assert.assertFalse("Java SDK tests: default role should not have forceunpublish permissions", xml.hasElement("forceunpublish", "permissions")); |
173 |
| -// Assert.assertFalse("Java SDK tests: default role should not have forcedisconnect permissions", xml.hasElement("forcedisconnect", "permissions")); |
174 |
| -// Assert.assertFalse("Java SDK tests: default role should not have record permissions", xml.hasElement("record", "permissions")); |
175 |
| -// Assert.assertFalse("Java SDK tests: default role should not have playback permissions", xml.hasElement("playback", "permissions")); |
176 |
| -// } |
177 |
| -// |
| 162 | + @Test |
| 163 | + public void testRoleDefault() throws |
| 164 | + OpenTokException, UnsupportedEncodingException, NoSuchAlgorithmException, SignatureException, |
| 165 | + InvalidKeyException { |
| 166 | + |
| 167 | + int apiKey = 123456; |
| 168 | + String apiSecret = "1234567890abcdef1234567890abcdef1234567890"; |
| 169 | + OpenTok opentok = new OpenTok(apiKey, apiSecret); |
| 170 | + String sessionId = "1_MX4xMjM0NTZ-flNhdCBNYXIgMTUgMTQ6NDI6MjMgUERUIDIwMTR-MC40OTAxMzAyNX4"; |
| 171 | + |
| 172 | + String token = opentok.generateToken(sessionId); |
| 173 | + |
| 174 | + assertNotNull(token); |
| 175 | + assertTrue(Helpers.verifyTokenSignature(token, apiSecret)); |
| 176 | + |
| 177 | + Map<String, String> tokenData = Helpers.decodeToken(token); |
| 178 | + assertEquals(Integer.toString(apiKey), tokenData.get("partner_id")); |
| 179 | + assertNotNull(tokenData.get("create_time")); |
| 180 | + assertNotNull(tokenData.get("nonce")); |
| 181 | + } |
| 182 | + |
178 | 183 | // @Test
|
179 | 184 | // public void testRolePublisher() throws OpenTokException {
|
180 | 185 | // Session s= sdk.createSession();
|
|
0 commit comments