Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1414 from christav/fix-credential-deletion
Browse files Browse the repository at this point in the history
Test runs no longer delete credentials.
  • Loading branch information
amarzavery committed Oct 22, 2014
2 parents c537bae + 4f3380c commit cb3a373
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 184 deletions.
16 changes: 7 additions & 9 deletions test/testlist.txt
Expand Up @@ -60,18 +60,18 @@ commands/cli.storage.table-tests.js
commands/cli.storage.queue-tests.js
commands/cli.storage.service-tests.js
util/git/linkrevisioncontrol-tests.js
util/utils-tests.js
util/set-tests.js
util/authentication/adalAuth-tests.js
util/profile/publishSettings-tests.js
util/profile/environment-addaccount-tests.js
util/profile/profile-tests.js
hdinsight/unit-cli-setup.js
hdinsight/unit-list-command.js
hdinsight/unit-show-command.js
hdinsight/unit-delete-command.js
hdinsight/unit-create-command.js
hdinsight/unit-config-commands.js
util/utils-tests.js
util/set-tests.js
util/authentication/adalAuth-tests.js
util/profile/publishSettings-tests.js
util/profile/environment-addaccount-tests.js
util/profile/profile-tests.js
# TODO: Not recording call to log service properly, disabling
#commands/cli.site.log.tail-tests.js
# Testing macos token management stuff
Expand All @@ -81,6 +81,4 @@ util/authentication/token-cache-encoding-tests.js
util/authentication/win-credstore-parser-tests.js
# Testing token cache class which works with adal-node
util/authentication/token-cache-tests.js
util/authentication/file-token-storage-tests.js
util/authentication/win-token-storage-tests.js
util/authentication/osx-token-storage-tests.js
util/authentication/token-storage-tests.js
61 changes: 0 additions & 61 deletions test/util/authentication/file-token-storage-tests.js

This file was deleted.

57 changes: 0 additions & 57 deletions test/util/authentication/osx-token-storage-tests.js

This file was deleted.

125 changes: 125 additions & 0 deletions test/util/authentication/token-storage-tests.js
@@ -0,0 +1,125 @@
/**
* Copyright (c) Microsoft. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

var fs = require('fs');
var os = require('os');
var path = require('path');
var uuid = require('node-uuid');

var should = require('should');

var WinTokenStorage = require('../../../lib/util/authentication/win-token-storage');
var OsxTokenStorage = require('../../../lib/util/authentication/osx-token-storage');
var FileTokenStore = require('../../../lib/util/authentication/file-token-storage');

function isWindows() {
return os.platform() === 'win32';
}

function isOsx() {
return os.platform() === 'darwin';
}

// This code will look a little weird.
// This function is used to define the actual
// tests for each storage. The outer
// describe calls will call this function to
// hook up the tests to the larger suite.
//
// This allows us to define the actual test criteria
// once and reuse them across multiple different
// storage implementations.
function addStorageTests(storage) {
it('is empty after clear is called', function(done) {
//add item to token storage
var newEntries = [{
"accessToken" : "ABCD",
"refreshToken" : "FREFDO",
"userId" : "foo@microsoft.com",
"tenantId" : "72f988bf-86f1-45aq-91ab-2d7gd011db47",
"_authority" : "https://login.windows.net/72f988bf-86f1-45aq-91ab-2d7gd011db47"}];
storage.addEntries(newEntries, [], function(err) {
if (err) { return done(err); }
//verify items in the storage
storage.loadEntries(function(err, entries) {
if (err) { return done(err); }
entries.length.should.be.greaterThan(0);
//clean the items in the storage
storage.clear(function(err) {
if (err) { return done(err); }
storage.loadEntries(function(err, entries) {
if (err) { return done(err); }
entries.should.have.length(0);
done();
});
});
});
});
});
}

// Test for windows, osx storage
[
['Win', isWindows, WinTokenStorage],
['OSX', isOsx, OsxTokenStorage],
].forEach(function (entry) {
var title = entry[0];
var canRun = entry[1];
var Store = entry[2];

if (canRun()) {
describe(title + ' credentials storage', function () {
var storage = new Store();
var originalTokenContents;

before(function (done) {
// Save contents of token store so we can put it back afterwards
originalTokenContents = storage.loadEntries(function (err, entries) {
originalTokenContents = entries;
done(err);
});
});

after(function (done) {
storage.clear(function () {
storage.addEntries(originalTokenContents, [], done);
});
});

addStorageTests(storage);
});
}
});

// And test for file storage

// Function to grap temp directory - case of function
// changed from node 0.8 to 0.10, so grab one or the other.
var getTmpDir = (os.tmpdir || os.tmpDir).bind(os);

describe('File credentials storage', function () {
var tempPath = path.join(getTmpDir(), 'store-' + uuid.v4());

var storage = new FileTokenStore(tempPath);

after(function() {
//delete file
fs.unlinkSync(tempPath);
});

addStorageTests(storage);
});
57 changes: 0 additions & 57 deletions test/util/authentication/win-token-storage-tests.js

This file was deleted.

0 comments on commit cb3a373

Please sign in to comment.