2019-11-15 19:01:13 -05:00
|
|
|
import io = require('@actions/io');
|
|
|
|
import fs = require('fs');
|
2019-11-20 13:25:21 -05:00
|
|
|
import os = require('os');
|
2019-11-15 19:01:13 -05:00
|
|
|
import path = require('path');
|
|
|
|
|
2019-11-20 13:25:21 -05:00
|
|
|
// make the os.homedir() call be local to the tests
|
|
|
|
jest.doMock('os', () => {
|
|
|
|
return {
|
|
|
|
homedir: jest.fn(() => __dirname)
|
|
|
|
};
|
|
|
|
});
|
2019-11-15 19:01:13 -05:00
|
|
|
|
|
|
|
import * as auth from '../src/auth';
|
|
|
|
|
2019-11-20 13:25:21 -05:00
|
|
|
const m2Dir = path.join(__dirname, auth.M2_DIR);
|
|
|
|
const settingsFile = path.join(m2Dir, auth.SETTINGS_FILE);
|
|
|
|
|
2019-11-15 19:01:13 -05:00
|
|
|
describe('auth tests', () => {
|
2019-11-20 13:25:21 -05:00
|
|
|
beforeEach(async () => {
|
2019-11-15 19:01:13 -05:00
|
|
|
await io.rmRF(m2Dir);
|
|
|
|
}, 300000);
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
try {
|
|
|
|
await io.rmRF(m2Dir);
|
|
|
|
} catch {
|
|
|
|
console.log('Failed to remove test directories');
|
|
|
|
}
|
|
|
|
}, 100000);
|
|
|
|
|
2019-11-20 13:25:21 -05:00
|
|
|
it('creates settings.xml with username and password', async () => {
|
2019-11-28 15:40:08 -05:00
|
|
|
const id = 'packages';
|
2019-11-15 19:01:13 -05:00
|
|
|
const username = 'bluebottle';
|
|
|
|
const password = 'SingleOrigin';
|
|
|
|
|
2019-11-28 15:40:08 -05:00
|
|
|
await auth.configAuthentication(id, username, password);
|
2019-11-15 19:01:13 -05:00
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(true);
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(true);
|
|
|
|
expect(fs.readFileSync(settingsFile, 'utf-8')).toEqual(
|
2019-11-28 15:40:08 -05:00
|
|
|
auth.generate(id, username, password)
|
2019-11-15 19:01:13 -05:00
|
|
|
);
|
|
|
|
}, 100000);
|
2019-11-20 13:25:21 -05:00
|
|
|
|
|
|
|
it('does not create settings.xml without username and / or password', async () => {
|
2019-11-28 15:40:08 -05:00
|
|
|
await auth.configAuthentication('FOO', '', '');
|
2019-11-20 13:25:21 -05:00
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(false);
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(false);
|
|
|
|
|
2019-11-28 15:40:08 -05:00
|
|
|
await auth.configAuthentication('', 'BAR', '');
|
2019-11-20 13:25:21 -05:00
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(false);
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(false);
|
|
|
|
|
2019-11-28 15:40:08 -05:00
|
|
|
await auth.configAuthentication('', '', 'BAZ');
|
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(false);
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(false);
|
|
|
|
|
|
|
|
await auth.configAuthentication('', '', '');
|
2019-11-20 13:25:21 -05:00
|
|
|
|
|
|
|
expect(fs.existsSync(m2Dir)).toBe(false);
|
|
|
|
expect(fs.existsSync(settingsFile)).toBe(false);
|
|
|
|
}, 100000);
|
2019-11-15 19:01:13 -05:00
|
|
|
});
|