Skip to content

Commit

Permalink
feat: only optionally pass username and password
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Jul 4, 2017
1 parent ac0f302 commit 5bcca6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/sftp-scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,19 @@ export default class SFTPScheme extends URLScheme {
url = new URL(url);
const sftp = new Client();

const conn = await sftp.connect({
const co = {
host: url.host,
port: url.port || this.constructor.defaultPort,
username: url.username,
password: '******'
});
port: url.port || this.constructor.defaultPort
};

if (url.username !== undefined) {
co.username = url.username;
}
if (url.password !== undefined) {
co.password = url.password;
}

const conn = await sftp.connect(co);

return conn.get(url.pathname);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/sftp-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import test from 'ava';
import SFTPScheme from '../src/sftp-scheme';

const url = require('url');
const path = require('path');

test('has name', t => {
const scheme = new SFTPScheme();
Expand All @@ -17,3 +18,12 @@ test('default port', t => {
const scheme = new SFTPScheme();
t.is(scheme.defaultPort, 22);
});

test('get', async t => {
const scheme = new SFTPScheme();
const content = await scheme.get(
'sftp://localhost/' + path.join(__dirname, '..', 'tests', 'sftp-test.js')
);

t.is(content, 'XXX');
});

0 comments on commit 5bcca6b

Please sign in to comment.