Esempio n. 1
0
 const cleanup = async () => {
   if (skipping()) {
     return;
   }
   if (mock) {
     exports.Roles.roles = [];
   } else {
     const cfg = await exports.load('cfg');
     const blobService = new azure.Blob({
       accountId: cfg.azure.accountId,
       accountKey: cfg.azure.accountKey,
     });
     try {
       await blobService.deleteContainer(exports.containerName);
     } catch (e) {
       if (e.code !== 'ResourceNotFound') {
         throw e;
       }
       // already deleted, so nothing to do
       // NOTE: really, this doesn't work -- the container doesn't register as existing
       // before the tests are complete, so we "leak" containers despite this effort to
       // clean them up.
     }
   }
 };
Esempio n. 2
0
  test('azureContainerSAS (read-write)', async () => {
    let result = await helper.apiClient.azureContainerSAS(
      helper.testaccount,
      'container-test',
      'read-write',
    );
    assert(typeof result.sas === 'string', 'Expected some form of string');
    assert(new Date(result.expiry).getTime() > new Date().getTime(),
      'Expected expiry to be in the future');

    let blob = new azure.Blob({
      accountId: helper.testaccount,
      sas: result.sas,
    });

    result = await blob.putBlob('container-test', 'blobTest', {type: 'BlockBlob'});
    assert(result);
  });
Esempio n. 3
0
  test('azureContainerSAS (read-only)', async () => {
    let result = await helper.apiClient.azureContainerSAS(
      helper.testaccount,
      'container-test',
      'read-only',
    );
    assert(typeof result.sas === 'string', 'Expected some form of string');
    assert(new Date(result.expiry).getTime() > new Date().getTime(),
      'Expected expiry to be in the future');

    let blob = new azure.Blob({
      accountId: helper.testaccount,
      sas: result.sas,
    });

    try {
      await blob.putBlob('container-test', 'blobTest', {type: 'BlockBlob'});
    } catch (error) {
      assert.equal(error.code, 'AuthorizationPermissionMismatch');
      return;
    }
    assert(false, 'This should have thrown an error because the write is not allowed.');
  });