From bb6c7a13b9d1b8e87dfc5a8f4495b9eb9319fa2c Mon Sep 17 00:00:00 2001 From: WolFi Date: Sun, 7 May 2017 18:21:11 +0200 Subject: PHPUnit fixes for custom locations --- launch_phpunit.sh | 8 -------- launch_phpunit.sh.sample | 8 ++++++++ tests/bootstrap.php | 12 ++++++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) delete mode 100755 launch_phpunit.sh create mode 100644 launch_phpunit.sh.sample diff --git a/launch_phpunit.sh b/launch_phpunit.sh deleted file mode 100755 index 70d80b58..00000000 --- a/launch_phpunit.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# Setup your testing environment paths -export SERVER_BASE_DIR=/var/www/html/nextcloud/ -export SERVER_CONFIG_DIR=/var/www/html/nextcloud/config/ -export SERVER_CONFIG_FILE=config.php - -# Launch the actual tests -phpunit -v $@ diff --git a/launch_phpunit.sh.sample b/launch_phpunit.sh.sample new file mode 100644 index 00000000..949113d7 --- /dev/null +++ b/launch_phpunit.sh.sample @@ -0,0 +1,8 @@ +#!/bin/bash +# Setup your testing environment paths +export SERVER_BASE_DIR=/var/www/html/ +export SERVER_CONFIG_DIR=/var/www/html/config/ +export SERVER_CONFIG_FILE=config.php + +# Launch the actual tests +phpunit -v $@ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5bee8f49..f9408862 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -9,9 +9,17 @@ * @copyright Sander Brand 2016 */ -require_once __DIR__ . '/../../../tests/bootstrap.php'; +$nc_require_base = getenv('SERVER_BASE_DIR'); + +if ($nc_require_base) { + require_once $nc_require_base . '/tests/bootstrap.php'; +} +else{ + require_once __DIR__ . '/../../../tests/bootstrap.php'; +} + require_once __DIR__ . '/../appinfo/autoload.php'; -#require_once __DIR__ . '/db/DatabaseHelperTest.php'; +require_once __DIR__ . '/db/DatabaseHelperTest.php'; // Fix for "Autoload path not allowed: .../tests/lib/testcase.php" -- cgit v1.2.3 From 3259c9dc3227503c818ea1246ed837f26dc187e8 Mon Sep 17 00:00:00 2001 From: WolFi Date: Sun, 7 May 2017 19:16:36 +0200 Subject: PHPUnit Database test fixes for latest nextloud --- phpunit.xml | 2 +- tests/db/DatabaseHelperTest.php | 11 ++++++++--- tests/unit/lib/BackgroundJob/ExpireCredentialsTest.php | 8 ++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 81137a1d..cb67e3ce 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,7 @@ ./tests/unit - ./tests/unit/lib/Db + diff --git a/tests/db/DatabaseHelperTest.php b/tests/db/DatabaseHelperTest.php index 87735dfe..fa78158f 100644 --- a/tests/db/DatabaseHelperTest.php +++ b/tests/db/DatabaseHelperTest.php @@ -48,16 +48,21 @@ abstract class DatabaseHelperTest extends PHPUnit_Extensions_Database_TestCase { * @var PHPUnit_Extensions_Database_DataSet_MysqlXmlDataSet[] */ protected $datasets; + + /** + * + * @var \OC\Server + */ + static protected $server = NULL; public function __construct() { parent::__construct(); } public function setUp() { - $server = new \OC\Server(getenv('SERVER_BASE_DIR'), new \OC\Config(getenv('SERVER_CONFIG_DIR'), getenv('SERVER_CONFIG_FILE'))); - $this->app_container = $server->query('passman'); + if (self::$server === NULL) self::$server = new \OC\Server(getenv('SERVER_BASE_DIR'), new \OC\Config(getenv('SERVER_CONFIG_DIR'), getenv('SERVER_CONFIG_FILE'))); - $this->db = $this->app_container->getServer()->getDatabaseConnection(); + $this->db = self::$server->getDatabaseConnection(); $this->datasets = []; $tables = $this->getTablesNames(); diff --git a/tests/unit/lib/BackgroundJob/ExpireCredentialsTest.php b/tests/unit/lib/BackgroundJob/ExpireCredentialsTest.php index a6d193dd..836a3b09 100644 --- a/tests/unit/lib/BackgroundJob/ExpireCredentialsTest.php +++ b/tests/unit/lib/BackgroundJob/ExpireCredentialsTest.php @@ -43,7 +43,11 @@ class ExpireCredentialsTest extends PHPUnit_Framework_TestCase { $jobList = $this->getMockBuilder('\OCP\BackgroundJob\IJobList')->getMock(); /** @var \OC\BackgroundJob\JobList $jobList */ - $backgroundJob->execute($jobList); - $this->assertTrue(true); + try { + $backgroundJob->execute($jobList); + } + catch (Exception $ex) { + $this->assertTrue(false); + } } } -- cgit v1.2.3 From 92ac904f26e1f98064c273179040b3272f5dc8c9 Mon Sep 17 00:00:00 2001 From: WolFi Date: Sun, 4 Jun 2017 19:07:10 +0200 Subject: Add custom_fields and files into the export FIX #305 --- js/app/controllers/export.js | 5 +-- js/exporters/exporter-csv.js | 73 +++++++++++++++++++++----------------- js/exporters/exporter-main.js | 81 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 124 insertions(+), 35 deletions(-) diff --git a/js/app/controllers/export.js b/js/app/controllers/export.js index b53b19b1..b284048c 100644 --- a/js/app/controllers/export.js +++ b/js/app/controllers/export.js @@ -31,7 +31,7 @@ * Controller of the passmanApp */ angular.module('passmanApp') - .controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', '$translate', function ($scope, $window, CredentialService, VaultService, $translate) { + .controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', 'FileService', 'EncryptService', '$translate', function ($scope, $window, CredentialService, VaultService, FileService, EncryptService, $translate) { $scope.available_exporters = []; $scope.active_vault = VaultService.getActiveVault(); $scope.confirm_key = ''; @@ -76,10 +76,11 @@ if (_credential.hidden === 0) { var key = CredentialService.getSharedKeyFromCredential(_credential); _credential = CredentialService.decryptCredential(_credential, key); + _credential.vault_key = key; _credentials.push(_credential); } } - $window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () { + $window.PassmanExporter[$scope.selectedExporter.id].export(_credentials, FileService, EncryptService).then(function () { _log($translate.instant('done')); }); } diff --git a/js/exporters/exporter-csv.js b/js/exporters/exporter-csv.js index 99494943..f3a25345 100644 --- a/js/exporters/exporter-csv.js +++ b/js/exporters/exporter-csv.js @@ -26,41 +26,52 @@ PassmanExporter.csv = { info: { name: 'CSV', id: 'csv', - description: 'Export credentials as csv.' + description: 'Export credentials as a csv file.' } }; -PassmanExporter.csv.export = function (credentials) { +PassmanExporter.csv.export = function (credentials, FileService, EncryptService) { /** global: C_Promise */ return new C_Promise(function () { - var _this = this; - var headers = ['label', 'username', 'password', 'email', 'description', 'tags', 'url']; - var file_data = '"' + headers.join('","') + '"\n'; - for (var i = 0; i < credentials.length; i++) { - var _credential = credentials[i]; - var row_data = []; - for (var h = 0; h < headers.length; h++) { - var field = headers[h]; - if (field === 'tags') { - var _tags = []; - for (var t = 0; t < _credential[field].length; t++) { - _tags.push(_credential[field][t].text); - } - var data = '[' + _tags.join(",") + ']'; - row_data.push('"' + data + '"'); - } else { - row_data.push('"' + _credential[field] + '"'); - } - } - var progress = { - percent: i / credentials.length * 100, - loaded: i, - total: credentials.length - }; - _this.call_progress(progress); - file_data += row_data.join(',') + "\n"; - } - _this.call_then(); - download(file_data, 'passman-export.csv'); + PassmanExporter.getCredentialsWithFiles(credentials, FileService, EncryptService).then((function(data){ + var headers = ['label', 'username', 'password', 'email', 'description', 'tags', 'url', 'custom_fields', 'files']; + var file_data = '"' + headers.join('","') + '"\n'; + for (var i = 0; i < credentials.length; i++) { + var _credential = credentials[i]; + var row_data = []; + for (var h = 0; h < headers.length; h++) { + var field = headers[h]; + if (field === 'tags') { + var _tags = []; + for (var t = 0; t < _credential[field].length; t++) { + _tags.push(_credential[field][t].text); + } + var data = '[' + _tags.join(",") + ']'; + row_data.push('"' + data + '"'); + } + else if (field == 'custom_fields' || field == 'files') { + var _fields = JSON.stringify(_credential[field]); + _fields = _fields.replaceAll('"', '""'); + row_data.push('"' + _fields + '"'); + } + else { + row_data.push('"' + _credential[field] + '"'); + } + } + var progress = { + percent: i / credentials.length * 100, + loaded: i, + total: credentials.length + }; + this.call_progress(progress); + file_data += row_data.join(',') + "\n"; + } + this.call_then(); + download(file_data, 'passman-export.csv'); + }).bind(this)).progress(function(progress) { + console.log(progress); + }); + + }); }; diff --git a/js/exporters/exporter-main.js b/js/exporters/exporter-main.js index 57cad60a..a4cf2034 100644 --- a/js/exporters/exporter-main.js +++ b/js/exporters/exporter-main.js @@ -22,6 +22,83 @@ // Importers should always start with this if (!window['PassmanExporter']) { - var PassmanExporter = {} -} + var PassmanExporter = { + getCredentialsWithFiles: function(credentials, FileService, EncryptService) { + var t = { + cred: credentials, + FS: FileService, + ES: EncryptService + } + + return new C_Promise(function() { + _this = this.parent; + var credentials = _this.cred; + this.parent.total = 0; + this.parent.finished = 0; + this.parent.fileGUID_cred = []; + this.parent.files = []; + this.parent.step = (function(file) { + this.parent.finished ++; + this.call_progress({ + total: this.parent.total, + finished: this.parent.finished + }); + + var dta = this.parent.fileGUID_cred[file.guid]; + + file.filename = this.parent.ES.decryptString(file.filename, this.parent.cred[dta.cred_pos].vault_key); + file.file_data = this.parent.ES.decryptString(file.file_data, this.parent.cred[dta.cred_pos].vault_key); + + // Files and custom_fields have different field structure + if (dta.on === 'files') { + this.parent.cred[dta.cred_pos][dta.on][dta.at] = file; + } + else { + this.parent.cred[dta.cred_pos][dta.on][dta.at].value = file; + } + + // We have finished downloading everything, so let's hand over job to somewhere else! + if (this.parent.total === this.parent.finished) { + this.call_then(this.parent.cred); + } + }).bind(this); + + for (var i = 0; i < credentials.length; i++) { + + var item = credentials[i]; + + // Custom fields + for (var c = 0; c < item.custom_fields.length; c++) { + var cf = item.custom_fields[c]; + if (cf.field_type === 'file') { + this.parent.total ++; + this.parent.fileGUID_cred[cf.value.guid] = { + cred_pos: i, + on: 'custom_fields', + at: c + }; + this.parent.FS.getFile(cf.value).then((function(data){ + this.parent.step(data); + }).bind(this)); + } + } + + // Also get all files + for (var c = 0; c < item.files.length; c++) { + this.parent.total ++; + this.parent.fileGUID_cred[item.files[c].guid] = { + cred_pos: i, + on: 'files', + at: c + }; + + this.parent.FS.getFile(item.files[c]).then((function(data){ + this.parent.step(data); + }).bind(this)); + } + } + }, t); + } + } +} -- cgit v1.2.3 From 8cde638391f2abbd4610b7188811ced528ec32f1 Mon Sep 17 00:00:00 2001 From: WolFi Date: Sun, 4 Jun 2017 20:14:30 +0200 Subject: ADD JSON exporter --- js/exporters/exporter-csv.js | 2 +- js/exporters/exporter-json.js | 64 +++++++++++++++++++++++++++++++++++++++++++ js/templates.js | 4 +-- templates/main.php | 1 + 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 js/exporters/exporter-json.js diff --git a/js/exporters/exporter-csv.js b/js/exporters/exporter-csv.js index f3a25345..f9b427ca 100644 --- a/js/exporters/exporter-csv.js +++ b/js/exporters/exporter-csv.js @@ -69,7 +69,7 @@ PassmanExporter.csv.export = function (credentials, FileService, EncryptService) this.call_then(); download(file_data, 'passman-export.csv'); }).bind(this)).progress(function(progress) { - console.log(progress); + }); diff --git a/js/exporters/exporter-json.js b/js/exporters/exporter-json.js new file mode 100644 index 00000000..92478293 --- /dev/null +++ b/js/exporters/exporter-json.js @@ -0,0 +1,64 @@ +/** + * Nextcloud - passman + * + * @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com) + * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es) + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +/** global: PassmanExporter */ +PassmanExporter.json = { + info: { + name: 'JSON', + id: 'json', + description: 'Export credentials as a JSON file.' + } +}; + +PassmanExporter.json.export = function (credentials, FileService, EncryptService) { + /** global: C_Promise */ + return new C_Promise(function () { + PassmanExporter.getCredentialsWithFiles(credentials, FileService, EncryptService).then((function(data){ + var _output = []; + for (var i = 0; i < credentials.length; i++) { + var _credential = angular.copy(credentials[i]); + + delete _credential.vault_key; + delete _credential.vault_id; + delete _credential.shared_key; + + console.log(_credential); + _output.push(_credential); + + var progress = { + percent: i / credentials.length * 100, + loaded: i, + total: credentials.length + }; + this.call_progress(progress); + } + var file_data = JSON.stringify(_output); + this.call_then(); + download(file_data, 'passman-export.json'); + }).bind(this)).progress(function(progress) { + console.log(progress); + }); + + + }); +}; diff --git a/js/templates.js b/js/templates.js index f97e8d4b..a9d98c30 100644 --- a/js/templates.js +++ b/js/templates.js @@ -87,7 +87,7 @@ angular.module('views/partials/forms/settings/sharing.html', []).run(['$template angular.module('views/partials/forms/settings/tool.html', []).run(['$templateCache', function ($templateCache) { 'use strict'; $templateCache.put('views/partials/forms/settings/tool.html', - '

{{ \'tool.intro\' | translate}}

{{ \'min.strength\' | translate}}

{{ \'scan.result.msg\' | translate}}

{{ \'label\' | translate}}{{ \'score\' | translate}}{{ \'password\' | translate}}{{ \'action\' | translate}}
{{result.label}}
'); + '

{{ \'tool.intro\' | translate}}

{{ \'min.strength\' | translate}}

{{ \'scan.result.msg\' | translate}}

{{ \'label\' | translate}}{{ \'score\' | translate}}{{ \'password\' | translate}}{{ \'action\' | translate}}
{{result.label}}
'); }]); angular.module('views/partials/forms/share_credential/basics.html', []).run(['$templateCache', function ($templateCache) { @@ -126,7 +126,7 @@ angular.module('views/show_vault.html', []).run(['$templateCache', function ($te 'use strict'; $templateCache.put('views/show_vault.html', '
+
{{ \'use.regex\' | translate }}
{{ ::tag.text}} {{ ::credential.label}}
  • {{ ::credential.label}}
    {{ ::tag.text}}

{{selectedCredential.label}}

'); + ' (settings.user_sharing_enabled === 1 || settings.user_sharing_enabled === \'1\' || settings.link_sharing_enabled === 1 || settings.link_sharing_enabled === \'1\')"> {{ \'share\' | translate}} '); }]); angular.module('views/vault_req_deletion.html', []).run(['$templateCache', function ($templateCache) { diff --git a/templates/main.php b/templates/main.php index aa10b94c..bea143e6 100644 --- a/templates/main.php +++ b/templates/main.php @@ -94,6 +94,7 @@ script('passman', 'importers/importer-passpackcsv'); script('passman', 'importers/importer-randomdata'); script('passman', 'exporters/exporter-main'); script('passman', 'exporters/exporter-csv'); +script('passman', 'exporters/exporter-json'); /*build-js-end*/ -- cgit v1.2.3 From 2c0455ead143d62fc4b485d8d197edd14726f48e Mon Sep 17 00:00:00 2001 From: brantje Date: Sat, 1 Jul 2017 16:05:32 +0200 Subject: Fix code style --- js/exporters/exporter-csv.js | 6 +++--- js/exporters/exporter-json.js | 7 +++---- js/exporters/exporter-main.js | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/js/exporters/exporter-csv.js b/js/exporters/exporter-csv.js index f9b427ca..8363a706 100644 --- a/js/exporters/exporter-csv.js +++ b/js/exporters/exporter-csv.js @@ -46,8 +46,8 @@ PassmanExporter.csv.export = function (credentials, FileService, EncryptService) for (var t = 0; t < _credential[field].length; t++) { _tags.push(_credential[field][t].text); } - var data = '[' + _tags.join(",") + ']'; - row_data.push('"' + data + '"'); + var tag_data = '[' + _tags.join(",") + ']'; + row_data.push('"' + tag_data + '"'); } else if (field == 'custom_fields' || field == 'files') { var _fields = JSON.stringify(_credential[field]); @@ -68,7 +68,7 @@ PassmanExporter.csv.export = function (credentials, FileService, EncryptService) } this.call_then(); download(file_data, 'passman-export.csv'); - }).bind(this)).progress(function(progress) { + }).bind(this)).progress(function() { }); diff --git a/js/exporters/exporter-json.js b/js/exporters/exporter-json.js index 92478293..dc20b68b 100644 --- a/js/exporters/exporter-json.js +++ b/js/exporters/exporter-json.js @@ -33,7 +33,7 @@ PassmanExporter.json = { PassmanExporter.json.export = function (credentials, FileService, EncryptService) { /** global: C_Promise */ return new C_Promise(function () { - PassmanExporter.getCredentialsWithFiles(credentials, FileService, EncryptService).then((function(data){ + PassmanExporter.getCredentialsWithFiles(credentials, FileService, EncryptService).then((function(){ var _output = []; for (var i = 0; i < credentials.length; i++) { var _credential = angular.copy(credentials[i]); @@ -42,7 +42,6 @@ PassmanExporter.json.export = function (credentials, FileService, EncryptService delete _credential.vault_id; delete _credential.shared_key; - console.log(_credential); _output.push(_credential); var progress = { @@ -55,8 +54,8 @@ PassmanExporter.json.export = function (credentials, FileService, EncryptService var file_data = JSON.stringify(_output); this.call_then(); download(file_data, 'passman-export.json'); - }).bind(this)).progress(function(progress) { - console.log(progress); + }).bind(this)).progress(function() { + }); diff --git a/js/exporters/exporter-main.js b/js/exporters/exporter-main.js index a4cf2034..53d1ab9b 100644 --- a/js/exporters/exporter-main.js +++ b/js/exporters/exporter-main.js @@ -28,10 +28,10 @@ if (!window['PassmanExporter']) { cred: credentials, FS: FileService, ES: EncryptService - } - + }; + /** global: C_Promise */ return new C_Promise(function() { - _this = this.parent; + var _this = this.parent; var credentials = _this.cred; this.parent.total = 0; this.parent.finished = 0; @@ -68,7 +68,7 @@ if (!window['PassmanExporter']) { var item = credentials[i]; // Custom fields - for (var c = 0; c < item.custom_fields.length; c++) { + for (c = 0; c < item.custom_fields.length; c++) { var cf = item.custom_fields[c]; if (cf.field_type === 'file') { this.parent.total ++; @@ -100,5 +100,5 @@ if (!window['PassmanExporter']) { } }, t); } - } + }; } -- cgit v1.2.3 From a1d1fc8ede2beca6a06b0963b75fc16bda269674 Mon Sep 17 00:00:00 2001 From: brantje Date: Sat, 1 Jul 2017 16:08:44 +0200 Subject: Update phpunit --- js/exporters/exporter-csv.js | 2 +- phpunit.integration.xml | 2 +- phpunit.xml | 6 +++--- tests/bootstrap.php | 8 +------- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/js/exporters/exporter-csv.js b/js/exporters/exporter-csv.js index 8363a706..70ec4740 100644 --- a/js/exporters/exporter-csv.js +++ b/js/exporters/exporter-csv.js @@ -33,7 +33,7 @@ PassmanExporter.csv = { PassmanExporter.csv.export = function (credentials, FileService, EncryptService) { /** global: C_Promise */ return new C_Promise(function () { - PassmanExporter.getCredentialsWithFiles(credentials, FileService, EncryptService).then((function(data){ + PassmanExporter.getCredentialsWithFiles(credentials, FileService, EncryptService).then((function(){ var headers = ['label', 'username', 'password', 'email', 'description', 'tags', 'url', 'custom_fields', 'files']; var file_data = '"' + headers.join('","') + '"\n'; for (var i = 0; i < credentials.length; i++) { diff --git a/phpunit.integration.xml b/phpunit.integration.xml index 32cba8af..9a9c27a6 100644 --- a/phpunit.integration.xml +++ b/phpunit.integration.xml @@ -1,7 +1,7 @@ - ./tests/integration + \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index cb67e3ce..3f796278 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -2,7 +2,7 @@ ./tests/unit - + ./tests/unit/lib/Db @@ -13,8 +13,8 @@ - - + + diff --git a/tests/bootstrap.php b/tests/bootstrap.php index f9408862..5bd36a9b 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -9,14 +9,8 @@ * @copyright Sander Brand 2016 */ -$nc_require_base = getenv('SERVER_BASE_DIR'); -if ($nc_require_base) { - require_once $nc_require_base . '/tests/bootstrap.php'; -} -else{ - require_once __DIR__ . '/../../../tests/bootstrap.php'; -} +require_once __DIR__ . '/../../../tests/bootstrap.php'; require_once __DIR__ . '/../appinfo/autoload.php'; require_once __DIR__ . '/db/DatabaseHelperTest.php'; -- cgit v1.2.3