From 220750f8870a9e99bf08be40b9b8ac3aa5b02f17 Mon Sep 17 00:00:00 2001 From: Fabrice Marsaud Date: Mon, 6 Jun 2016 12:11:29 +0200 Subject: [PATCH] fix(SMB): use of `@` and `:` chars in passwords (#8) Fixes #4. --- packages/xo-remote-parser/src/index.js | 8 ++++-- packages/xo-remote-parser/src/index.spec.js | 28 +++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/xo-remote-parser/src/index.js b/packages/xo-remote-parser/src/index.js index de2098afb..bc323e821 100644 --- a/packages/xo-remote-parser/src/index.js +++ b/packages/xo-remote-parser/src/index.js @@ -18,8 +18,12 @@ export const parse = (remote) => { remote.share = share } else if (type === 'smb') { remote.type = 'smb' - const [auth, smb] = rest.split('@') - const [username, password] = auth.split(':') + const lastArobas = rest.lastIndexOf('@') + const smb = rest.slice(lastArobas) + const auth = rest.slice(0, lastArobas) + const firstColon = auth.indexOf(':') + const username = auth.slice(0, firstColon) + const password = auth.slice(firstColon) const [domain, sh] = smb.split('\\\\') const [host, path] = sh.split('\0') remote.host = host diff --git a/packages/xo-remote-parser/src/index.spec.js b/packages/xo-remote-parser/src/index.spec.js index 2d4b56074..8e1cf5815 100644 --- a/packages/xo-remote-parser/src/index.spec.js +++ b/packages/xo-remote-parser/src/index.spec.js @@ -24,6 +24,26 @@ const SMB = { password: 'password' } +const SMB_AROBAS = { + url: 'smb://Administrator:pass@word@toto\\\\192.168.100.225\\smb\0', + type: 'smb', + host: '192.168.100.225\\smb', + path: undefined, + domain: 'toto', + username: 'Administrator', + password: 'pass@word' +} + +const SMB_COLON = { + url: 'smb://Administrator:pass:word@toto\\\\192.168.100.225\\smb\0', + type: 'smb', + host: '192.168.100.225\\smb', + path: undefined, + domain: 'toto', + username: 'Administrator', + password: 'pass:word' +} + const parseData = { file: { url: 'file://var/lib/xoa/backup', // Remotes formatted before fixing #7 will not break when reparses @@ -31,7 +51,9 @@ const parseData = { path: '/var/lib/xoa/backup' }, fileFixed: FILE_FIXED, - smb: SMB + smb: SMB, + 'smb@inPassword': SMB_AROBAS, + 'smb:inPassword': SMB_COLON } const formatData = { @@ -41,7 +63,9 @@ const formatData = { path: '/var/lib/xoa/backup' }, fileFixed: FILE_FIXED, - smb: SMB + smb: SMB, + 'smb@inPassword': SMB_AROBAS, + 'smb:inPassword': SMB_COLON } // -------------------------------------------------------------------