Beispiel #1
0
 it('should get the server settings', () => {
   manager.dispose();
   const serverSettings = ServerConnection.makeSettings();
   const token = serverSettings.token;
   manager = new SessionManager({ serverSettings });
   expect(manager.serverSettings.token).to.equal(token);
 });
Beispiel #2
0
  describe('#getDownloadUrl()', () => {
    const settings = ServerConnection.makeSettings({
      baseUrl: 'http://foo'
    });

    it('should get the url of a file', async () => {
      const drive = new Drive({ serverSettings: settings });
      const test1 = drive.getDownloadUrl('bar.txt');
      const test2 = drive.getDownloadUrl('fizz/buzz/bar.txt');
      const test3 = drive.getDownloadUrl('/bar.txt');
      const urls = await Promise.all([test1, test2, test3]);
      expect(urls[0]).to.equal('http://foo/files/bar.txt');
      expect(urls[1]).to.equal('http://foo/files/fizz/buzz/bar.txt');
      expect(urls[2]).to.equal('http://foo/files/bar.txt');
    });

    it('should encode characters', async () => {
      const drive = new Drive({ serverSettings: settings });
      const url = await drive.getDownloadUrl('b ar?3.txt');
      expect(url).to.equal('http://foo/files/b%20ar%3F3.txt');
    });

    it('should not handle relative paths', async () => {
      const drive = new Drive({ serverSettings: settings });
      const url = await drive.getDownloadUrl('fizz/../bar.txt');
      expect(url).to.equal('http://foo/files/fizz/../bar.txt');
    });
  });
Beispiel #3
0
 it('should accept options', () => {
   manager.dispose();
   manager = new TerminalManager({
     serverSettings: ServerConnection.makeSettings()
   });
   expect(manager).to.be.an.instanceof(TerminalManager);
 });
 it('should use baseUrl for wsUrl', () => {
   const conf: Partial<ServerConnection.ISettings> = {
     baseUrl: 'https://host/path'
   };
   const settings = ServerConnection.makeSettings(conf);
   expect(settings.baseUrl).to.equal(conf.baseUrl);
   expect(settings.wsUrl).to.equal('wss://host/path');
 });
 it('should create a server error from a server response', async () => {
   const settings = getRequestHandler(200, 'hi');
   const init = { body: 'hi', method: 'POST' };
   const response = await ServerConnection.makeRequest(
     settings.baseUrl,
     init,
     settings
   );
   const err = new ServerConnection.ResponseError(response);
   expect(err.message).to.equal('Invalid response: 200 OK');
 });
 it('should make a request to the server', async () => {
   const settings = getRequestHandler(200, 'hello');
   const response = await ServerConnection.makeRequest(
     settings.baseUrl,
     {},
     settings
   );
   expect(response.statusText).to.equal('OK');
   const data = await response.json();
   expect(data).to.equal('hello');
 });
 it('should handle overrides', () => {
   const defaults: Partial<ServerConnection.ISettings> = {
     baseUrl: 'foo',
     wsUrl: 'bar',
     init: {
       credentials: 'same-origin'
     },
     token: 'baz'
   };
   const settings = ServerConnection.makeSettings(defaults);
   expect(settings.baseUrl).to.equal(defaults.baseUrl);
   expect(settings.wsUrl).to.equal(defaults.wsUrl);
   expect(settings.token).to.equal(defaults.token);
   expect(settings.init.credentials).to.equal(defaults.init.credentials);
 });
Beispiel #8
0
  describe('SettingManager', () => {
    const manager = new SettingManager({
      serverSettings: ServerConnection.makeSettings({ pageUrl: 'lab' })
    });

    describe('#constructor()', () => {
      it('should accept no options', () => {
        const manager = new SettingManager();
        expect(manager).to.be.an.instanceof(SettingManager);
      });

      it('should accept options', () => {
        const manager = new SettingManager({
          serverSettings: ServerConnection.makeSettings()
        });
        expect(manager).to.be.an.instanceof(SettingManager);
      });
    });

    describe('#serverSettings', () => {
      it('should be the server settings', () => {
        const baseUrl = 'foo';
        const serverSettings = ServerConnection.makeSettings({ baseUrl });
        const manager = new SettingManager({ serverSettings });
        expect(manager.serverSettings.baseUrl).to.equal(baseUrl);
      });
    });

    describe('#fetch()', () => {
      it('should fetch settings for an extension', async () => {
        const id = '@jupyterlab/apputils-extension:themes';

        expect((await manager.fetch(id)).id).to.equal(id);
      });
    });

    describe('#save()', () => {
      it('should save a setting', async () => {
        const id = '@jupyterlab/apputils-extension:themes';
        const theme = 'Foo Theme';
        const raw = `{"theme": "${theme}"}`;

        await manager.save(id, raw);
        expect(JSON.parse((await manager.fetch(id)).raw).theme).to.equal(theme);
      });
    });
  });
Beispiel #9
0
  describe('#getDownloadUrl()', () => {
    const settings = ServerConnection.makeSettings({
      baseUrl: 'http://foo'
    });

    it('should get the url of a file', async () => {
      const drive = new Drive({ serverSettings: settings });
      const contents = new ContentsManager({ defaultDrive: drive });
      const test1 = contents.getDownloadUrl('bar.txt');
      const test2 = contents.getDownloadUrl('fizz/buzz/bar.txt');
      const test3 = contents.getDownloadUrl('/bar.txt');
      const urls = await Promise.all([test1, test2, test3]);
      expect(urls[0]).to.equal('http://foo/files/bar.txt');
      expect(urls[1]).to.equal('http://foo/files/fizz/buzz/bar.txt');
      expect(urls[2]).to.equal('http://foo/files/bar.txt');
    });

    it('should encode characters', async () => {
      const drive = new Drive({ serverSettings: settings });
      const contents = new ContentsManager({ defaultDrive: drive });
      const url = await contents.getDownloadUrl('b ar?3.txt');
      expect(url).to.equal('http://foo/files/b%20ar%3F3.txt');
    });

    it('should not handle relative paths', async () => {
      const drive = new Drive({ serverSettings: settings });
      const contents = new ContentsManager({ defaultDrive: drive });
      const url = await contents.getDownloadUrl('fizz/../bar.txt');
      expect(url).to.equal('http://foo/files/fizz/../bar.txt');
    });

    it('should get the url of a file from an additional drive', async () => {
      const contents = new ContentsManager();
      const other = new Drive({ name: 'other', serverSettings: settings });
      contents.addDrive(other);
      const test1 = contents.getDownloadUrl('other:bar.txt');
      const test2 = contents.getDownloadUrl('other:fizz/buzz/bar.txt');
      const test3 = contents.getDownloadUrl('other:/bar.txt');
      const urls = await Promise.all([test1, test2, test3]);
      expect(urls[0]).to.equal('http://foo/files/bar.txt');
      expect(urls[1]).to.equal('http://foo/files/fizz/buzz/bar.txt');
      expect(urls[2]).to.equal('http://foo/files/bar.txt');
    });
  });
 it('should use default settings', () => {
   const settings = ServerConnection.makeSettings();
   expect(settings.baseUrl).to.equal(PageConfig.getBaseUrl());
   expect(settings.wsUrl).to.equal(PageConfig.getWsUrl());
   expect(settings.token).to.equal(PageConfig.getOption('token'));
 });