Ejemplo n.º 1
0
Archivo: xlm.ts Proyecto: BitGo/BitGoJS
        it('should resolve a stellar address into an account', co(function *() {
          const stellarAddress = 'test12345*lobstr.co';
          const accountId = 'GB5MEYCR4V2NRZH4NSI465ZEFRXPBZ74P43BMYN7AWVMAI5NNCKNZSVY';

          nock('https://lobstr.co')
          .get('/.well-known/stellar.toml')
          .reply(200, 'FEDERATION_SERVER=\'https://lobstr.co/federation\'');

          nock('https://lobstr.co')
          .get('/federation')
          .query({
            q: stellarAddress,
            type: 'name'
          })
          .reply(200, {
            stellar_address: stellarAddress,
            account_id: accountId
          });

          const res = yield basecoin.federationLookupByName(stellarAddress);
          res.should.have.property('stellar_address');
          res.should.have.property('account_id');
          res.stellar_address.should.equal(stellarAddress);
          res.account_id.should.equal(accountId);
        }));
Ejemplo n.º 2
0
export function getMockFirewallRules(){
    nock('https://management.azure.com', {
        reqheaders: {
            "authorization": "Bearer DUMMY_ACCESS_TOKEN",
            "content-type": "application/json; charset=utf-8"
        }
    }).put("/subscriptions/MOCK_SUBSCRIPTION_ID/resourceGroups/MOCK_RESOURCE_GROUP_NAME/providers/Microsoft.DBforMySQL/servers/MOCK_SERVER_NAME/firewallRules/IPAddressRange_MOCK_RELEASE_ID12345?api-version=2017-12-01").reply(201, {
        "id": "/subscriptions/MOCK_SUBSCRIPTION_ID/resourceGroups/MOCK_RESOURCE_GROUP_NAME/providers/Microsoft.DBforMySQL/servers/MOCK_SERVER_NAME/firewallRules/IPAddressRange_MOCKID",
        "name": "rule1",
        "type": "Microsoft.DBforMySQL/servers/firewallRules",
        "properties": {
          "startIpAddress": "0.0.0.0",
          "endIpAddress": "255.255.255.255"
        }
      }).persist();

    nock('https://management.azure.com', {
        reqheaders: {
            "authorization": "Bearer DUMMY_ACCESS_TOKEN",
            "content-type": "application/json; charset=utf-8"
        }
    })
    .delete("/subscriptions/MOCK_SUBSCRIPTION_ID/resourceGroups/MOCK_RESOURCE_GROUP_NAME/providers/Microsoft.DBforMySQL/servers/MOCK_SERVER_NAME/firewallRules/IPAddressRange_MOCK_RELEASE_ID12345?api-version=2017-12-01")
    .reply(200).persist();

}
Ejemplo n.º 3
0
    it('should correctly pass through the krsSpecific param when creating backup keychains', co(function *() {
      const params = {
        label: 'my_wallet',
        backupXpubProvider: 'test',
        passphrase: 'test123',
        userKey: 'xpub123',
        krsSpecific: { coverage: 'insurance', expensive: true, howExpensive: 25 }
      };

      // bitgo key
      nock(bgUrl)
      .post('/api/v2/tbtc/key', _.matches({ source: 'bitgo' }))
      .reply(200);

      // user key
      nock(bgUrl)
      .post('/api/v2/tbtc/key', _.conforms({ pub: (p) => p.startsWith('xpub') }))
      .reply(200);

      // backup key
      nock(bgUrl)
      .post('/api/v2/tbtc/key', _.matches({ source: 'backup', provider: params.backupXpubProvider, krsSpecific: { coverage: 'insurance', expensive: true, howExpensive: 25 } }))
      .reply(200);

      // wallet
      nock(bgUrl)
      .post('/api/v2/tbtc/wallet')
      .reply(200);

      yield wallets.generateWallet(params);
    }));
Ejemplo n.º 4
0
test('checks access tokens against third party API', async (t) => {
  /* eslint-disable camelcase */
  let app = new AppAcceptanceTest();
  nock('https://graph.facebook.com')
    .post('/oauth/access_token')
    .reply(200, querystring.stringify({
      access_token: 'foo',
      refresh_token: 'bar'
    }));
  nock('https://graph.facebook.com/')
    .get('/v2.5/me')
    .query({ access_token: 'foo' })
    .reply(200, {
      id: '123'
    });

  let login = await app.post('/users/auth/oauth/facebook?code=abc123');
  t.is(login.status, 201);
  app.setHeader('Authorization', `TOKEN ${ login.body.token }`);

  let me = await app.get('/users/auth/me');
  t.is(me.status, 200);
  t.is(me.body.facebookId, '123');
  /* eslint-enable camelcase */
});
Ejemplo n.º 5
0
function setUpNock() {

    nock('http://redvstt-lab43:8080', { "encodedQueryParams": true })
        .get('/job/ArtifactEngineJob/6/api/json')
        .query({ "tree": "artifacts[*]" })
        .basicAuth({
            user: '******',
            pass: '******'
        })
        .reply(200, { "artifacts": [{ "displayPath": "file1.pdb", "fileName": "file1.pdb", "relativePath": "Extensions/ArtifactEngine/TestData/Jenkins/file1.pdb" }, { "displayPath": "file2.txt", "fileName": "file2.txt", "relativePath": "Extensions/ArtifactEngine/TestData/Jenkins/folder1/file2.txt" }] });

    nock('http://redvstt-lab43:8080', { "encodedQueryParams": true })
        .get('/job/ArtifactEngineJob/6/artifact/Extensions/ArtifactEngine/TestData/Jenkins/file1.pdb')
        .basicAuth({
            user: '******',
            pass: '******'
        })
        .reply(200, "dummyFileContent");

    nock('http://redvstt-lab43:8080', { "encodedQueryParams": true })
        .get('/job/ArtifactEngineJob/6/artifact/Extensions/ArtifactEngine/TestData/Jenkins/folder1/file2.txt')
        .basicAuth({
            user: '******',
            pass: '******'
        })
        .reply(200, "dummyFolderContent");
}
Ejemplo n.º 6
0
    it('should correctly disable krs emails when creating backup keychains', co(function *() {
      const params = {
        label: 'my_wallet',
        disableKRSEmail: true,
        backupXpubProvider: 'test',
        passphrase: 'test123',
        userKey: 'xpub123'
      };

      // bitgo key
      nock(bgUrl)
      .post('/api/v2/tbtc/key', _.matches({ source: 'bitgo' }))
      .reply(200);

      // user key
      nock(bgUrl)
      .post('/api/v2/tbtc/key', _.conforms({ pub: (p) => p.startsWith('xpub') }))
      .reply(200);

      // backup key
      nock(bgUrl)
      .post('/api/v2/tbtc/key', _.matches({ source: 'backup', provider: params.backupXpubProvider, disableKRSEmail: true }))
      .reply(200);

      // wallet
      nock(bgUrl)
      .post('/api/v2/tbtc/wallet')
      .reply(200);

      yield wallets.generateWallet(params);
    }));
Ejemplo n.º 7
0
    it('should handle ECONNRESET errors from the proxy server', co(function *() {
      const path = '/api/v2/fakeroute';

      // client constants are retrieved upon BitGo
      // object creation so they need to be nocked
      nock(common.Environments.test.uri)
      .get('/api/v1/client/constants')
      .reply(200, {});

      // first request to ping endpoint should time out
      nock(common.Environments.test.uri)
      .get(path)
      .socketDelay(1000)
      .reply(200);

      // we should return 500 in the case of a timeout
      let pingRes = yield agent.get(path).send({});
      pingRes.should.have.status(500);

      nock(common.Environments.test.uri)
      .get(path)
      .reply(200);

      pingRes = yield agent.get(path).send({});
      pingRes.should.have.status(200);
    }));
 it('should support global request params', async () => {
   const google = new GoogleApis();
   google.options({params: {myParam: '123'}});
   const drive = google.drive('v2');
   nock(Utils.baseUrl).get('/drive/v2/files/123?myParam=123').reply(200);
   const res = await drive.files.get({fileId: '123'});
   // If the default param handling is broken, query might be undefined, thus
   // concealing the assertion message with some generic "cannot call
   // .indexOf of undefined"
   let query = Utils.getQs(res) || '';
   assert.notEqual(
       query.indexOf('myParam=123'), -1, 'Default param not found in query');
   // I can't explain why, but the `nock.enableNetConnect()` call below simply
   // won't work unless I call `nock.cleanAll()` first.
   nock.cleanAll();
   nock.enableNetConnect();
   const d = await Utils.loadApi(google, 'drive', 'v2');
   nock.disableNetConnect();
   nock(Utils.baseUrl).get('/drive/v2/files/123?myParam=123').reply(200);
   // tslint:disable-next-line no-any
   const res3 = await (d as any).files.get({fileId: '123'});
   // If the default param handling is broken, query might be undefined,
   // thus concealing the assertion message with some generic "cannot
   // call .indexOf of undefined"
   query = Utils.getQs(res3) || '';
   assert.notEqual(
       query.indexOf('myParam=123'), -1, 'Default param not found in query');
 });
beforeAll(() => {

  // mock service endpoint

  const defaultResponse = {
    type: 'success',
    value: {
      id: 2000,
      joke: 'Chuck Norris can write to an output stream.',
      categories: [],
    },
  };
  nock(process.env.JOKE_SERVICE_URL!)
    .get('/jokes/random')
    .reply(200, defaultResponse);

  const nerdyResponse = {
    type: 'success',
    value: {
      id: 1000,
      joke: "Mock Chuck Norris's database has only one table, 'Kick', which he DROPs frequently.",
      categories: [
        'nerdy',
      ],
    },
  };
  nock(process.env.JOKE_SERVICE_URL!)
    .get('/jokes/random')
    .query({ limitTo: '[nerdy]' })
    .reply(200, nerdyResponse);
});
Ejemplo n.º 10
0
 it('should be null if params passed are in path', async () => {
   nock(Utils.baseUrl).get('/drive/v2/files/123').reply(200);
   const res = await localDrive.files.get({fileId: '123'});
   assert.equal(Utils.getQs(res), null);
   nock(Utils.baseUrl).get('/drive/v2/files/123').reply(200);
   const res2 = await remoteDrive.files.get({fileId: '123'});
   assert.equal(Utils.getQs(res), null);
 });