lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceTest.java
/**
     * Enter client without permission to do so, check exception
     * Tests RTP8h
     */
Enter client without permission to do so, check exception
Tests RTP8h
Enter client without permission to do so check exception Tests RTP8h
@Test
    public void presence_enter_without_permission() throws AblyException {
        String channelName = "presence_enter_without_permission" + testParams.name;
        AblyRealtime ably = null;
        try {
            /* init ably for token */
            ClientOptions optsForToken = createOptions(testVars.keys[0].keyStr);
            final AblyRest ablyForToken = new AblyRest(optsForToken);
            /* get first token */
            Auth.TokenParams tokenParams = new Auth.TokenParams();
            Capability capability = new Capability();
            capability.addResource(channelName, "publish"); /* no presence permission! */
            tokenParams.capability = capability.toString();
            tokenParams.clientId = testClientId1;
            Auth.TokenDetails token = ablyForToken.auth.requestToken(tokenParams, null);
            assertNotNull("Expected token value", token.token);
            ClientOptions opts = createOptions();
            opts.clientId = testClientId1;
            opts.tokenDetails = token;
            ably = new AblyRealtime(opts);
            Channel channel = ably.channels.get(channelName);
            ChannelWaiter channelWaiter = new ChannelWaiter(channel);
            channel.attach();
            channelWaiter.waitFor(ChannelState.attached);
            CompletionWaiter enterWaiter = new CompletionWaiter();
            channel.presence.enterClient(testClientId1, null, enterWaiter);
            ErrorInfo enterError = enterWaiter.waitFor();
            assertNotNull("Verify enter client failed", enterError);
        } finally {
            if (ably != null)
                ably.close();
        }
    }
@ Test public void presence_enter_without_permission ( ) throws AblyException { String channelName = "presence_enter_without_permission" + testParams . name ; AblyRealtime ably = null ; try { /* init ably for token */ ClientOptions optsForToken = createOptions ( testVars . keys [ 0 ] . keyStr ) ; final AblyRest ablyForToken = new AblyRest ( optsForToken ) ; /* get first token */ Auth . TokenParams tokenParams = new Auth . TokenParams ( ) ; Capability capability = new Capability ( ) ; capability . addResource ( channelName , "publish" ) ; /* no presence permission! */ tokenParams . capability = capability . toString ( ) ; tokenParams . clientId = testClientId1 ; Auth . TokenDetails token = ablyForToken . auth . requestToken ( tokenParams , null ) ; assertNotNull ( "Expected token value" , token . token ) ; ClientOptions opts = createOptions ( ) ; opts . clientId = testClientId1 ; opts . tokenDetails = token ; ably = new AblyRealtime ( opts ) ; Channel channel = ably . channels . get ( channelName ) ; ChannelWaiter channelWaiter = new ChannelWaiter ( channel ) ; channel . attach ( ) ; channelWaiter . waitFor ( ChannelState . attached ) ; CompletionWaiter enterWaiter = new CompletionWaiter ( ) ; channel . presence . enterClient ( testClientId1 , null , enterWaiter ) ; ErrorInfo enterError = enterWaiter . waitFor ( ) ; assertNotNull ( "Verify enter client failed" , enterError ) ; } finally { if ( ably != null ) ably . close ( ) ; } }
Enter client without permission to do so, check exception
 Tests RTP8h
Enter client without permission to do so check exception Tests RTP8h