Ejemplo n.º 1
0
        it(`gets emitted`, (done) => {
          const bufferStateSpy = sinon.spy();
          const onlineSpy = sinon.spy();

          mercury.on(`event:mercury.buffer_state`, bufferStateSpy);
          mercury.on(`online`, onlineSpy);

          Socket.getWebSocketConstructor.returns(() => {
            process.nextTick(() => {
              assert.isTrue(mercury.connecting, `Mercury is still connecting`);
              assert.isFalse(mercury.connected, `Mercury has not yet connected`);
              assert.notCalled(onlineSpy, `Mercury has not yet fired the online event`);
              mockWebSocket.emit(`message`, {
                data: JSON.stringify({
                  data: {
                    eventType: `mercury.buffer_state`
                  }
                })
              });

              promiseTick(1)
                .then(() => {
                  assert.calledOnce(bufferStateSpy);
                  done();
                })
                .catch(done);

            });
            return mockWebSocket;
          });

          // eslint-disable-next-line
          mockWebSocket.send = function noop() {};
          mercury.connect();
        });
Ejemplo n.º 2
0
    function makeSpark(href = 'https://example.com', csrfToken = undefined, config = {}) {
      const mockWindow = {
        history: {
          replaceState(a, b, location) {
            mockWindow.location.href = location;
          }
        },
        location: {
          href
        },
        sessionStorage: {
          getItem: sinon.stub().returns(csrfToken),
          removeItem: sinon.spy(),
          setItem: sinon.spy()
        }
      };

      sinon.spy(mockWindow.history, 'replaceState');

      const spark = new MockSpark({
        children: {
          authorization: Authorization,
          credentials: Credentials
        },
        request: sinon.stub().returns(Promise.resolve({body: {access_token: 'AT', token_type: 'Fake', refresh_token: 'RT'}})),
        config: merge({
          credentials: {
            idbroker: {
              url: process.env.IDBROKER_BASE_URL,
              defaultUrl: process.env.IDBROKER_BASE_URL
            },
            identity: {
              url: process.env.IDENTITY_BASE_URL,
              defaultUrl: process.env.IDENTITY_BASE_URL
            },
            activationUrl: `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/token/v1/actions/UserActivation/invoke`,
            authorizeUrl: `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/authorize`,
            setPasswordUrl: `${process.env.IDBROKER_BASE_URL || 'https://identity.webex.com'}/identity/scim/v1/Users`,
            logoutUrl: `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/logout`,
            // eslint-disable-next-line camelcase
            client_id: 'fake',
            // eslint-disable-next-line camelcase
            client_secret: 'fake',
            // eslint-disable-next-line camelcase
            redirect_uri: 'http://example.com',
            // eslint-disable-next-line camelcase
            scope: 'scope:one',
            refreshCallback: () => Promise.resolve()
          }
        }, config),
        getWindow() {
          return mockWindow;
        }
      });

      return spark;
    }
Ejemplo n.º 3
0
    beforeEach(() => {
      spark = new MockSpark({
        children: {
          device: Device
        }
      });

      spark.internal.device._processRegistrationSuccess({body: cloneDeep(deviceFixture)});

      deviceFeaturesChangeDeveloperSpy = sinon.spy();
      deviceChangeFeaturesDeveloperSpy = sinon.spy();
      deviceChangeFeaturesSpy = sinon.spy();
      deviceChangeSpy = sinon.spy();
      sparkChangeSpy = sinon.spy();
      sparkChangeDeviceSpy = sinon.spy();
      sparkChangeDeviceFeaturesSpy = sinon.spy();
      sparkChangeDeviceFeaturesDeveloperSpy = sinon.spy();

      spark.internal.device.features.on('change:developer', deviceFeaturesChangeDeveloperSpy);
      spark.internal.device.on('change:features.developer', deviceChangeFeaturesDeveloperSpy);
      spark.internal.device.on('change:features', deviceChangeFeaturesSpy);
      spark.internal.device.on('change', deviceChangeSpy);
      spark.on('change', sparkChangeSpy);
      spark.on('change:internal.device', sparkChangeDeviceSpy);
      spark.on('change:internal.device.features', sparkChangeDeviceFeaturesSpy);
      spark.on('change:internal.device.features.developer', sparkChangeDeviceFeaturesDeveloperSpy);
    });
Ejemplo n.º 4
0
 it(`emits download progress events for non-encrypted files`, () => {
   const spy = sinon.spy();
   return spark.internal.conversation.download({url: makeLocalUrl(`/sample-image-small-one.png`)})
     .on(`progress`, spy)
     .then((f) => assert.eventually.isTrue(fh.isMatchingFile(f, sampleImageSmallOnePng)))
     .then(() => assert.called(spy));
 });
Ejemplo n.º 5
0
      it(`stops emitting message events`, () => {
        const spy = sinon.spy();
        mercury.on(`event:status.start_typing`, spy);

        return mercury.connect()
          .then(() => {
            assert.isTrue(mercury.connected, `Mercury is connected`);
            assert.isFalse(mercury.connecting, `Mercury is not connecting`);

            assert.notCalled(spy);
            mockWebSocket.emit(`message`, {data: statusStartTypingMessage});
          })
          .then(() => {
            assert.calledOnce(spy);

            const promise = mercury.disconnect();
            mockWebSocket.emit(`message`, {data: statusStartTypingMessage});
            mockWebSocket.emit(`close`, {
              code: 1000,
              reason: `Done`
            });
            mockWebSocket.emit(`message`, {data: statusStartTypingMessage});
            return promise;
          })

          .then(() => {
            mockWebSocket.emit(`message`, {data: statusStartTypingMessage});
            assert.calledOnce(spy);
          });
      });
Ejemplo n.º 6
0
      it(`emits pongs separately from other messages`, () => {
        const pongSpy = sinon.spy();
        socket.on(`pong`, pongSpy);

        mockWebSocket.emit(`message`, {
          data: JSON.stringify({
            sequenceNumber: 5,
            id: `mockid1`,
            type: `pong`
          })
        });

        assert.calledOnce(pongSpy);
        assert.notCalled(spy);

        mockWebSocket.emit(`message`, {
          data: JSON.stringify({
            sequenceNumber: 6,
            id: `mockid2`
          })
        });

        assert.calledOnce(pongSpy);
        assert.calledOnce(spy);
      });
Ejemplo n.º 7
0
        skipInBrowser(it)(`periodically refreshes the device`, () => {
          sinon.spy(spark.internal.device, `refresh`);
          spark.internal.device.register();
          return promiseTick(80)
            .then(() => {
              assert.notCalled(spark.internal.device.refresh);
              clock.tick(config.device.ephemeralDeviceTTL / 2 * 1000);
              assert.notCalled(spark.internal.device.refresh);
              return promiseTick(80);

            })
            .then(() => {
              clock.tick(60 * 1000);
              return promiseTick(80);
            })
            .then(() => {
              assert.calledOnce(spark.internal.device.refresh);
              return promiseTick(4);
            })
            .then(() => {
              clock.tick(config.device.ephemeralDeviceTTL / 2 * 1000);
              assert.calledOnce(spark.internal.device.refresh);
              clock.tick(60 * 1000);
              assert.calledTwice(spark.internal.device.refresh);
            });
        });
Ejemplo n.º 8
0
      it('keeps the parameter when it has keys', () => {
        const spark = makeSpark(undefined, undefined, {
          credentials: {
            clientType: 'confidential'
          }
        });
        const location = {
          query: {
            code: 'code',
            state: {
              csrf_token: 'token',
              key: 'value'
            }
          }
        };

        sinon.spy(spark.authorization, '_cleanUrl');
        spark.authorization._cleanUrl(location);
        assert.called(spark.getWindow().history.replaceState);
        const {href} = spark.getWindow().location;

        assert.isDefined(href);
        assert.equal(href, `?state=${base64.encode(JSON.stringify({key: 'value'}))}`);
        assert.notInclude(href, 'csrf_token');
      });
Ejemplo n.º 9
0
    function makeSpark(href = `https://example.com`, csrfToken = undefined, config = {}) {
      const mockWindow = {
        history: {
          replaceState(a, b, location) {
            mockWindow.location.href = location;
          }
        },
        location: {
          href
        },
        sessionStorage: {
          getItem: sinon.stub().returns(csrfToken),
          removeItem: sinon.spy(),
          setItem: sinon.spy()
        }
      };

      sinon.spy(mockWindow.history, `replaceState`);

      const spark = new MockSpark({
        children: {
          authorization: Authorization,
          credentials: Credentials
        },
        request: sinon.stub().returns(Promise.resolve({body: {access_token: `AT`, token_type: `Fake`, refresh_token: `RT`}})),
        config: merge({
          credentials: {
            authorizeUrl: `https://idbroker.webex.com/idb/oauth2/v1/authorize`,
            logoutUrl: `https://idbroker.webex.com/idb/oauth2/v1/logout`,
            // eslint-disable-next-line camelcase
            client_id: `fake`,
            // eslint-disable-next-line camelcase
            client_secret: `fake`,
            // eslint-disable-next-line camelcase
            redirect_uri: `http://example.com`,
            // eslint-disable-next-line camelcase
            scope: `scope:one`,
            refreshCallback: () => Promise.resolve()
          }
        }, config),
        getWindow() {
          return mockWindow;
        }
      });

      return spark;
    }
Ejemplo n.º 10
0
        it('should stop the stream, and trigger a media:stopped event when the local stream stops', async () => {
          const spy = sinon.spy(meeting, 'trigger');

          Media.stopStream = sinon.stub().returns(Promise.resolve());
          await meeting.closeLocalStream();
          assert.calledOnce(spy);
          assert.calledWith(spy, 'media:stopped', {type: 'local'});
        });
Ejemplo n.º 11
0
        it('listens to the self addmitted guest event', (done) => {
          const spy = sinon.spy(meeting, 'trigger');

          meeting.locusInfo.emit('SELF_ADMITTED_GUEST', test1);
          assert.calledOnce(spy);
          assert.calledWith(spy, 'meeting:self:guestAdmitted', {payload: test1});
          done();
        });
Ejemplo n.º 12
0
 .then(() => {
   assert.equal(call.status, `connected`);
   assert.equal(mccoyCall.status, `connected`);
   const hangupSpy = sinon.spy(call, `hangup`);
   mccoyCall.hangup();
   return call.when(`disconnected`)
     .then(() => assert.called(hangupSpy));
 });
Ejemplo n.º 13
0
 it(`emits messages that arrive before authorization completes`, () => {
   const spy = sinon.spy();
   spark.internal.mercury.on(`event:mercury.buffer_state`, spy);
   return spark.internal.mercury.connect()
     .then(() => {
       assert.calledOnce(spy);
     });
 });
Ejemplo n.º 14
0
 it(`emits the \`online\` event`, () => {
   const spy = sinon.spy();
   mercury.on(`online`, spy);
   const promise = mercury.connect();
   mockWebSocket.open();
   return promise
     .then(() => assert.called(spy));
 });
Ejemplo n.º 15
0
          it.skip('adds video to the call', () => {
            const call = spock.spark.phone.dial(mccoy.email, {
              constraints: {
                audio: true,
                video: false
              }
            });
            let mccoyCall;

            sinon.spy(spock.spark.internal.locus, 'updateMedia');

            return Promise.all([
              expectCallIncomingEvent(mccoy.spark.phone)
                .then((c) => {
                  mccoyCall = c;

                  return handleErrorEvent(c, () => c.answer());
                }),
              handleErrorEvent(call, () => expectConnectedEvent(call)
                .then(() => assertLocusMediaState(call, {
                  sendingAudio: true,
                  sendingVideo: false,
                  receivingAudio: true,
                  receivingVideo: false
                }))
                .then(() => Promise.all([
                  call.toggleSendingVideo(),
                  call.toggleReceivingVideo()
                ]))
                .then(() => assertLocusMediaState(call, {
                  sendingAudio: true,
                  sendingVideo: true,
                  receivingAudio: true,
                  receivingVideo: true
                }))
                .then(() => {
                  assert.equal(remoteParticipant(mccoyCall.locus)
                    .status
                    .audioStatus
                    .toLowerCase(), boolToStatus(true, true));
                  assert.equal(remoteParticipant(mccoyCall.locus)
                    .status
                    .videoStatus
                    .toLowerCase(), boolToStatus(true, false));

                  return Promise.all([
                    call.toggleSendingVideo(),
                    call.toggleReceivingVideo()
                  ]);
                }))
                .then(() => assertLocusMediaState(call, {
                  sendingAudio: true,
                  sendingVideo: false,
                  receivingAudio: true,
                  receivingVideo: false
                }))
            ]);
          });
Ejemplo n.º 16
0
 it(`emits all the correct events`, () => {
   let remoteCall;
   const localCallStatusSpy = sinon.spy();
   const remoteCallStatusSpy = sinon.spy();
   const handler = handleErrorEvent(spock.spark.phone.dial(mccoy.email),
     (localCall) => {
       localCall.on(`change:status`, () => localCallStatusSpy(localCall.status));
       assert.equal(localCall.status, `initiated`);
       return mccoy.spark.phone.when(`call:incoming`)
         .then(([c]) => {
           remoteCall = c;
           remoteCall.on(`change:status`, () => remoteCallStatusSpy(remoteCall.status));
           assert.equal(remoteCall.status, `initiated`);
           return Promise.all([
             remoteCall.acknowledge(),
             localCall.when(`ringing`)
           ]);
         })
         .then(() => assert.equal(localCall.status, `ringing`))
         .then(() => Promise.all([
           remoteCall.answer(),
           localCall.when(`connected`),
           remoteCall.when(`connected`)
         ]))
         .then(() => {
           assert.equal(localCall.status, `connected`);
           assert.equal(remoteCall.status, `connected`);
         })
         .then(() => Promise.all([
           localCall.when(`disconnected`),
           remoteCall.when(`disconnected`),
           localCall.hangup()
         ]))
         .then(() => {
           assert.equal(localCallStatusSpy.args[0][0], `ringing`);
           assert.equal(localCallStatusSpy.args[1][0], `connected`);
           assert.equal(localCallStatusSpy.args[2][0], `disconnected`);
           assert.equal(remoteCallStatusSpy.args[0][0], `connected`);
           assert.equal(remoteCallStatusSpy.args[1][0], `disconnected`);
           assert.equal(localCall.status, `disconnected`);
           assert.equal(remoteCall.status, `disconnected`);
         });
     });
   return handler;
 });
Ejemplo n.º 17
0
      it(`gets triggered when something fails in a non-promise-returning method`, () => {
        this.timeout(60000);
        const call = spock.spark.phone.dial(`no one`);

        const errorSpy = sinon.spy();
        call.on(`error`, errorSpy);
        return call.when(`error`)
          .then(() => assert.called(errorSpy));
      });
Ejemplo n.º 18
0
 .then((users) => {
   spark = new CiscoSpark({
     credentials: {
       supertoken: users[0].token
     }
   });
   sinon.spy(spark.internal.device, `unregister`);
   return spark.internal.device.register();
 }));
Ejemplo n.º 19
0
        it('should stop the stream, and trigger a media:stopped event when the remote stream stops', async () => {
          const spy = sinon.spy(meeting, 'trigger');

          Media.stopStream = sinon.stub().returns(Promise.resolve());
          await meeting.closeRemoteStream();
          assert.calledOnce(spy);
          assert.calledWith(spy, 'media:stopped', {type: 'remote'});
          assert.notOk(meeting.mediaProperties.shareStream);
        });
Ejemplo n.º 20
0
      skipInNode(it)('provides an interface for file upload events', () => {
        const spy = sinon.spy();
        const share = spark.internal.conversation.makeShare(conversation);
        const emitter = share.add(sampleImageSmallOnePng);

        emitter.on('progress', spy);

        return spark.internal.conversation.share(conversation, share)
          .then(() => assert.called(spy));
      });
Ejemplo n.º 21
0
      it('does not put CI info in state for #initiateAuthorizationCodeGrant() when default CI', () => {
        const spark = makeSpark(`http://example.com/?code=5&state=${base64.encode(JSON.stringify({csrf_token: 'csrf_token'}))}`, 'csrf_token');

        const spy = sinon.spy(spark.authorization, 'initiateAuthorizationCodeGrant');

        return spark.authorization.initiateLogin()
          .then(() => {
            assert.neverCalledWith(spy, sinon.match.has('state', sinon.match.has('idbroker', 'notDefaultIdBroker', 'identity', 'notDefaultIdBroker')));
          });
      });
Ejemplo n.º 22
0
 it(`is a noop for outbound calls`, () => handleErrorEvent(spock.spark.phone.dial(mccoy.id), (call) => {
   sinon.spy(call, `_join`);
   return assert.isFulfilled(call.answer())
     .then(() => {
       // We called _join to create the call
       assert.calledWith(call._join, `create`);
       // But we did not call _join when we invoked answer()
       assert.neverCalledWith(call._join, `join`);
     });
 }));
Ejemplo n.º 23
0
        it('should trigger a media:ready event when remote stream track ontrack is fired', () => {
          const spy = sinon.spy(meeting, 'trigger');
          const pc = {};

          meeting.setRemoteStream(pc);
          pc.ontrack({streams: [test1]});
          assert.calledOnce(spy);
          assert.calledWith(spy, 'media:ready', {type: 'remote', stream: test1});
          assert.equal(meeting.mediaProperties.remoteStream, test1);
        });
Ejemplo n.º 24
0
        beforeEach('sets web-ha-messaging to false', () => {
          spark.internal.device.features.developer.set([{
            key: 'web-ha-messaging',
            val: 'false',
            value: false,
            mutable: true,
            lastModified: '2015-06-29T20:02:48.033Z'
          }]);

          sinon.spy(spark.internal.device, 'markUrlFailedAndGetNew');
        });
Ejemplo n.º 25
0
      beforeEach(() => {
        spark = new MockSpark({
          children: {
            credentials: Credentials
          },
          config: cloneDeep(config),
          request: sinon.spy()
        });

        interceptor = Reflect.apply(RedirectInterceptor.create, spark, []);
      });
Ejemplo n.º 26
0
        it(`emits the Mercury envelope named by the Mercury event's eventType`, () => {
          const startSpy = sinon.spy();
          const stopSpy = sinon.spy();

          mercury.on(`event:status.start_typing`, startSpy);
          mercury.on(`event:status.stop_typing`, stopSpy);

          const promise = mercury.connect();
          mockWebSocket.open();
          return promise
            .then(() => {
              mockWebSocket.emit(`message`, {data: JSON.stringify(statusStartTypingMessage)});
              return promiseTick(1);
            })
            .then(() => {
              assert.calledOnce(startSpy);
              assert.notCalled(stopSpy);
              assert.calledWith(startSpy, statusStartTypingMessage);
            });
        });
Ejemplo n.º 27
0
        it('should trigger a media:ready event with local stream', () => {
          const spy = sinon.spy(meeting, 'trigger');

          meeting.mediaProperties.setLocalStream = sinon.stub().returns(true);
          meeting.setLocalStream(test1);
          assert.calledOnce(spy);
          assert.calledWith(spy, 'media:ready', {type: 'local', stream: undefined});
          assert.calledOnce(meeting.mediaProperties.setLocalStream);
          assert.calledWith(meeting.mediaProperties.setLocalStream, test1);
          assert.equal(meeting.mediaProperties.localStream, undefined);
        });
Ejemplo n.º 28
0
          it(`emits the \`online\` event`, () => {
            const spy = sinon.spy();
            mercury.on(`online`, spy);

            const promise = mercury.connect();
            mockWebSocket.open();
            return promise
              .then(() => assert.calledOnce(spy))
              .then(() => mockWebSocket.emit(`close`, {code: 1000, reason: `Idle`}))
              .then(() => mercury.connect())
              .then(() => assert.calledTwice(spy));
          });
Ejemplo n.º 29
0
          it('should trigger an unsuccessful reconnection and return a promise', async () => {
            const spy = sinon.spy(meeting, 'trigger');

            meeting.reconnectionManager = new ReconnectionManager({config: {reconnection: {retry: {backOff: 1}}}});
            meeting.reconnectionManager.reconnect = sinon.stub().returns(Promise.reject());
            meeting.reconnectionManager.reset = sinon.stub().returns(true);
            await meeting.reconnect().catch(() => {
              assert.calledOnce(spy);
              assert.calledWith(spy, 'meeting:reconnectionFailure', {error: sinon.match.any});
              assert.calledOnce(meeting.reconnectionManager.reset);
            });
          });
Ejemplo n.º 30
0
    beforeEach(() => {
      spark = new MockSpark({
        children: {
          metrics: Metrics
        }
      });

      spark.config.metrics = config.metrics;
      metrics = spark.internal.metrics;

      spark.request = function(options) {
        return Promise.resolve({
          statusCode: 204,
          body: undefined,
          options
        });
      };
      sinon.spy(spark, `request`);
      sinon.spy(metrics, `postPreLoginMetric`);
      sinon.spy(metrics, `aliasUser`);
      sinon.spy(metrics, `submitCallDiagnosticEvents`);
    });