diff --git a/Brocfile.js b/Brocfile.js index e28fb83..7984f5a 100644 --- a/Brocfile.js +++ b/Brocfile.js @@ -89,6 +89,15 @@ trees.push( }) ); +if (app.env === 'development' || app.env === 'test') { + trees.push( + pickFiles('tests/dummyData', { + srcDir: '/', + destDir: '/data' + }) + ); +} + trees.push(app.toTree()); var mergeTrees = require('broccoli-merge-trees'); module.exports = mergeTrees(trees); diff --git a/api/classes/model.php b/api/classes/model.php index 1e52299..511a872 100644 --- a/api/classes/model.php +++ b/api/classes/model.php @@ -185,13 +185,19 @@ class Model { $data = self::convertFromStorage($storageObject); + if(method_exists($model, 'restoreLegacySupportHook')) { + $model->restoreLegacySupportHook($data); + } + $properties = array_merge( static::ENCRYPTED_PROPERTIES, static::PLAIN_PROPERTIES, static::SERVER_PROPERTIES ); foreach ($properties as $property) { - $model->set($property, $data->$property); + if (isset($data->$property)) { + $model->set($property, $data->$property); + } } if (static::PROOF_KEY_KNOWLEDGE === 'save') { diff --git a/api/classes/poll.php b/api/classes/poll.php index c53190b..e097002 100644 --- a/api/classes/poll.php +++ b/api/classes/poll.php @@ -91,7 +91,7 @@ class Poll extends model { protected function getUsers() { $users = []; - $userDir = DATA_FOLDER . $this->get('id') . '/users/'; + $userDir = DATA_FOLDER . $this->get('id') . '/user/'; if (is_dir($userDir)) { $dir = opendir($userDir); while(false !== ($file = readdir($dir))) { @@ -129,4 +129,20 @@ class Poll extends model { return false; } } + + protected function restoreLegacySupportHook(&$data) { + if (!isset($data->version) || $data->version === 'v0.3-0') { + if (isset($data->poll) && is_object($data->poll)) { + $data = $data->poll; + } + + foreach($data as $key => $value) { + if (strpos($key, 'encrypted') === 0) { + $newKey = lcfirst(substr($key, 9)); + $data->$newKey = $data->$key; + unset($data->$key); + } + } + } + } } diff --git a/api/classes/user.php b/api/classes/user.php index 25036e9..fff56a9 100644 --- a/api/classes/user.php +++ b/api/classes/user.php @@ -38,7 +38,7 @@ class User extends Model { } protected function getDir() { - return $this->getPollDir() . 'users/'; + return $this->getPollDir() . 'user/'; } protected function getPollDir() { @@ -74,4 +74,20 @@ class User extends Model { Poll::isValidId($parts[0]) && intval($parts[1]) == $parts[1]; } + + protected function restoreLegacySupportHook(&$data) { + if (!isset($data->version) || $data->version === 'v0.3-0') { + if (isset($data->user) && is_object($data->user)) { + $data = $data->user; + } + + foreach($data as $key => $value) { + if (strpos($key, 'encrypted') === 0) { + $newKey = lcfirst(substr($key, 9)); + $data->$newKey = $data->$key; + unset($data->$key); + } + } + } + } } diff --git a/api/tests/api/CreateAnotherUserCept.php b/api/tests/api/CreateAnotherUserCept.php index 2880915..5a0d604 100644 --- a/api/tests/api/CreateAnotherUserCept.php +++ b/api/tests/api/CreateAnotherUserCept.php @@ -6,7 +6,7 @@ $pollJson = '{"anonymousUser":"{\"iv\":\"gVHZSXyMm10Fn+kDooa7uw==\",\"v\":1,\"it $userJson = '{"user":{"name":"{\"iv\":\"kizIqK7FPNmRuQB7VHsMOw==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mhO9ROu+dr4=\",\"ct\":\"UsYMzrww3HKR8vl2TKVE\"}","selections":"{\"iv\":\"hRmiZagEhQVhw2cg6UJNrg==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mhO9ROu+dr4=\",\"ct\":\"2zIPGpiSC6wJHRoAMYBFPXx3qmlZg0Z/Jt/15mY+sHPLCqoAn97TKGN6KIvl/5gmgCFqLQFNo6uppCTUhljoV5y2kMtGvm0g3+NdpcejWGOeMACDPcp1mpXII87ZTfC6WrtxcWCB6UGYN8EynOdndFTGp+WVZnXCCya7YPThk/QRwoHoPWS6+TJFT9WeHV4i4kUIg2K3kdz3Op7S/c7l7KbOc8GsyjZzv0bRDnAm68/+FlJyZnvfMfU8vTxExsIsd0pBy4JBV4hg9SlCPectb5BAvBCULLDPA08prf262RUmVKJ+M3P1+5KkBQcnQwnUW/fzAQ7lqA==\"}","creationDate":"{\"iv\":\"xqdDY/A7MHLeAsoU9S/j+A==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mhO9ROu+dr4=\",\"ct\":\"TQOhbjveZbvdiyYpxfwNyu5pi1PLia9FApJJRmr3QoyrWA==\"}","version":"v0.3.0+0ae62f31","poll":"' . $pollId . '"}}'; $pollDir = 'tests/_tmp/data/' . $pollId . '/'; -$userDir = $pollDir . 'users/'; +$userDir = $pollDir . 'user/'; mkdir($pollDir); file_put_contents($pollDir . 'poll_data', $pollJson, LOCK_EX); file_put_contents($pollDir . 'key_knowledge', $proofKeyKnowledge, LOCK_EX); diff --git a/api/tests/api/GetLegacyPollWithUsersCept.php b/api/tests/api/GetLegacyPollWithUsersCept.php new file mode 100644 index 0000000..66cf247 --- /dev/null +++ b/api/tests/api/GetLegacyPollWithUsersCept.php @@ -0,0 +1,85 @@ +wantTo('get an existing legacy (v0.3.0) poll with users'); +$I->sendGET('/polls/' . $pollId); +$I->seeResponseCodeIs(200); +$I->seeResponseIsJson(); + +$pollData = json_decode($pollJson, true)["poll"]; +unset($pollData["serverExpirationDate"]); +foreach($pollData as $key => $value) { + if (strpos($key, 'encrypted') === 0) { + $key = lcfirst(substr($key, 9)); + } + else { + $key = $key; + } + $I->seeResponseContainsJson( + array( + 'poll' => array( + $key => $value + ) + ) + ); +} + +$I->seeResponseContainsJson(["poll" => ["id" => $pollId]]); +$I->dontSeeResponseJsonMatchesJsonPath('poll.serverExpirationDate'); +$I->seeResponseJsonMatchesJsonPath('poll.users'); +$users = $I->grabDataFromResponseByJsonPath('poll.users')[0]; +\PHPUnit_Framework_Assert::assertTrue( + is_array($users), + 'user should be an array' +); +\PHPUnit_Framework_Assert::assertEquals( + count($users), + 2, + 'user array should contain 2 users' +); + +function wellformUser($user) { + $return = $user["user"]; + foreach ($return as $key => $value) { + if(strpos($key, 'encrypted') === 0) { + $return[lcfirst(substr($key, 9))] = $value; + unset($return[$key]); + } + } + return $return; +} +$I->seeResponseContainsJson([ + "poll" => [ + "users" => [ + wellformUser(json_decode($user1Json, true)), + wellformUser(json_decode($user2Json, true)) + ] + ] +]); + +$I->seeResponseJsonMatchesJsonPath('poll.users.0.id'); +$I->seeResponseJsonMatchesJsonPath('poll.users.1.id'); +$user1Id = $I->grabDataFromResponseByJsonPath('poll.users.0.id')[0]; +$user2Id = $I->grabDataFromResponseByJsonPath('poll.users.1.id')[0]; +\PHPUnit_Framework_Assert::assertTrue( + $user1Id !== $user2Id, + 'user ids are unique' +); +\PHPUnit_Framework_Assert::assertEquals( + explode('_', $user1Id)[0], + $pollId, + 'user id starts by poll id' +); diff --git a/api/tests/api/GetPollWithUsersCept.php b/api/tests/api/GetPollWithUsersCept.php index 2c72f84..6ef8304 100644 --- a/api/tests/api/GetPollWithUsersCept.php +++ b/api/tests/api/GetPollWithUsersCept.php @@ -6,7 +6,7 @@ $user1Json = '{"name":"{\"iv\":\"GJXPSYYmTVfEsst31BD92w==\",\"v\":1,\"iter\":100 $user2Json = '{"name":"{\"iv\":\"DVNTCOFfACEOrgtVNVMyww==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mhO9ROu+dr4=\",\"ct\":\"eug7bstOm7T\/CCFs32o=\"}","selections":"{\"iv\":\"ubEuXoXzw4QFuzjAyvXC6w==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mhO9ROu+dr4=\",\"ct\":\"PfQ4v4hkBf+S0GX7JmnIp2LO5sh\/jg9nEIPn8NeU2Gn9Rb7cqsjCLgKOQ2xkiIzCyimVBOYg0fjGCyzM\/b6ZPQnY+86teNGogEteD4fjqGHhO832FNOy7Oci0YC8VAM1x9SlQNBI9V+vFc706JbZgwA8JY46UMiGK3HU49pgbYMpdnWEmt4dGzGrLMnNbh4J1Or5JydKmrp4dXaMiiggSXhmUTgBJSRhF7dxQm16oaA1lJpCWoQBvu+WTJv34LnBXHbgg6JcAEEONaQRw1jmMeqo36tQJxSdjiVfcDWzMifWiz\/nhQMqDHkc19iOAmDBo2Rf+yrGWA==\"}","creationDate":"{\"iv\":\"Sj4pVW\/maHa8DUNFHhyUrw==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mhO9ROu+dr4=\",\"ct\":\"HaY9MtEzVmEg3dxtI\/pfaIrsivBJSNeC5l5iJHQrvyYQGA==\"}","version":"v0.3.0+0ae62f31","poll":"l3zyFJUWcQ"}'; $pollDir = 'tests/_tmp/data/' . $pollId . '/'; -$userDir = $pollDir . 'users/'; +$userDir = $pollDir . 'user/'; mkdir($pollDir); file_put_contents($pollDir . 'poll_data', $pollJson); mkdir($userDir); diff --git a/app/serializers/application.js b/app/serializers/application.js index 67b32ae..e20e6a5 100644 --- a/app/serializers/application.js +++ b/app/serializers/application.js @@ -25,31 +25,12 @@ export default DS.RESTSerializer.extend({ var decryptionKey = dummyRecord.get('encryption.key'); dummyRecord.destroyRecord(); - // legacy support for versions before v0.4.0 - if (!resourceHash.version || resourceHash.version === 'v0.3-0') - { - for(var key in resourceHash) { - // attributes got renamed in v0.4.0 - // encrypted prefix was removed - if(key.indexOf('encrypted') === 0) { - let newKey; - // remove prefix 'encrypted' - newKey = key.substring(9); - // first char to lower case - newKey = newKey[0].toLowerCase() + newKey.slice(1); - // set correct attribute name in hash and delete wrong one - resourceHash[newKey] = resourceHash[key]; - delete resourceHash[key]; - } - } - } - // run before serialization of attribute hash modelClass.eachAttribute(function(key, attributes) { if ( attributes.options.encrypted !== false ) { - if (typeof resourceHash[key] !== "undefined") { + if (typeof resourceHash[key] !== "undefined" && resourceHash[key] !== null) { try { resourceHash[key] = JSON.parse( sjcl.decrypt(decryptionKey, resourceHash[key]) diff --git a/tests/acceptance/legacy-support-test.js b/tests/acceptance/legacy-support-test.js deleted file mode 100644 index b44d768..0000000 --- a/tests/acceptance/legacy-support-test.js +++ /dev/null @@ -1,97 +0,0 @@ -import Ember from 'ember'; -import { module, test } from 'qunit'; -import startApp from 'croodle/tests/helpers/start-app'; -import Pretender from 'pretender'; -/* jshint proto: true */ -/* global moment */ - -var application, server; - -module('Acceptance | legacy support', { - beforeEach: function() { - application = startApp(); - application.__container__.lookup('adapter:application').__proto__.namespace = ''; - - server = new Pretender(); - }, - - afterEach: function() { - server.shutdown(); - - Ember.run(application, 'destroy'); - } -}); - -test('show a default poll created with v0.3.0', function(assert) { - var id = 'xDF516KCyI', - encryptionKey = 'i7yjbKl8X6rObvnN9YuuwCIRdBxx5443T4GTKSny'; - - server.get('/polls/' + id, function() { - return [ - 200, - { "Content-Type": "application/json" }, - '{"poll":{"encryptedTitle":"{\\"iv\\":\\"UX3elmjGqNKrEG8VaBQKBQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"nXvJ+mvLM8jWOg2VUMsFtk4MwEc0cDdb2Ult3KgwX\\/Qcckq9ynuemGrB\\"}","encryptedDescription":"{\\"iv\\":\\"XOd2nsI7tPQhJq5TpcTaOQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"Km2lCbdP9UnTG1bCHHWZVSr8itBPDZHPRTR25lTxX\\/kyzbpHv9AalmwW7ho9U+VdT2D4HcjCQXS6gBppkAvouhbhJJBcoCTYyQQWRprLDhlRJDdlXoxvLAQ8mkprYjPbd9hDSgP+wCgeaP4srVfIZ1Nzs\\/aCVX5dZVy0h3xo\\"}","encryptedPollType":"{\\"iv\\":\\"42b5q7Edr81oZQe\\/JbaUhA==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"KL9G5\\/9mUWIMUde8MSPrsL8mVA==\\"}","encryptedAnswerType":"{\\"iv\\":\\"D6ILcXVWJjJrqVcOvIpaPQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"UfNLQ\\/\\/oyu1k\\/QGFMj1z\\"}","encryptedAnswers":"{\\"iv\\":\\"NJ+zUA8q\\/1kCTZ6RvUtVWA==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"RG2+2EMqIcomBHhTYvLj2\\/tk5sO\\/JcNUDO9nSW\\/6I2eHD6qICQyvh9AANEDca39fGSsyIDWdEGb5vUBO698U3tKmbLT5Wc+VnpUibZNkKudrhwyAW6ZBXqQbACFHcwIrEDzAcmcJEEpF2LfB07VSBAZv3+uBc1L8KJdpYpnnJEk8Vrh3XuICqFK4i9AxJEhoWu+WG4D8K8G+cVnK20JYVUykNwO5cwqxOGWOb04gTPVT8zflX6z99ur1u6QqpIMO9hUUX54y25XuARbm\\/wCLsXAifM\\/K8b0vWjrRYgcnTvno\\/rk=\\"}","encryptedOptions":"{\\"iv\\":\\"zbNGX5ve+E0ciwgQOwiUyQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"iC7lhzhChLa0dNZWUw9EEQQbTKwnsFQuGhslARzstggj4AG1f1mOdd1ExipGkye66TQ5SyCV3A==\\"}","encryptedCreationDate":"{\\"iv\\":\\"tX2yNkFpx9mEk1DB1UdFGg==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"546yKMVB2jRhjUtqJWT\\/C+irV7JjG0WgJp3+Ag3QkMny6Q==\\"}","encryptedForceAnswer":"{\\"iv\\":\\"Erp3h7I11PeHZhL60+\\/4CQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"yTm6HgIhNC8UHSzP\\"}","encryptedAnonymousUser":"{\\"iv\\":\\"c6EOvuJYw8eNCxnFAJ0eTw==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"CO7J61aKRneZno7bCg==\\"}","encryptedIsDateTime":"{\\"iv\\":\\"1iHh8UZYj3Aqyl\\/nM06fRQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"x6b6MeO8ipO2K38GxA==\\"}","encryptedTimezone":"{\\"iv\\":\\"kZc64suFcN5PO3VsRvGQbw==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"ataOh9JNWpvhjA==\\"}","version":"v0.3-0","id":"xDF516KCyI","users":[{"encryptedName":"{\\"iv\\":\\"pE4nQuD924O+ODNYRWJ7jg==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"m4EzKUdHStkFjcvt5q0MlusOESk4ew==\\"}","encryptedSelections":"{\\"iv\\":\\"VXGMuKcGpizAwFvpztXM3A==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"HeIxQ\\/bU11G0\\/fDXUkKzO94RpK72Ytnof2Hm11pqY3Lwot7kfxpLJ6DD3kKGVYruMe375Hii3bsXOjAroMAe+KUQ9SG0y0aOhJRCc\\/P8O6sAg6NPwBx\\/71LXxxaLr8ORDFzyCwZx3kjXWNS7j017w\\/zJNHJbzY7CimRaG8dtbK5UFFjb28T1SRmLzOvaQ4yJgaTbsnGBIeMrVI9qiEQ1Uo44bRqT6Js9OBzykt\\/aU4FXce3iJ3hctbeYqPRx\\/+TJTS07Wf6LYZG0VRhFhRqmIJLky3PhyZsXgwtY0gJJDyLa9ctN7POurxoFXzyk4fk1AANtHUDVbA==\\"}","encryptedCreationDate":"{\\"iv\\":\\"GUDjdSw2hW2e0wBhwoPx3Q==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Sv34vSd\\/b14=\\",\\"ct\\":\\"zMRHnbJF28bidi6+9uN9T+CvlrvtZzi4nrLeqQuwHpUj5Q==\\"}","version":"v0.3-0","poll":"xDF516KCyI","id":"0"}]}}' - ]; - }); - - visit('/poll/' + id + '?encryptionKey=' + encryptionKey); - - andThen(function() { - pollTitleEqual(assert, 'default poll created with v0.3.0'); - pollDescriptionEqual(assert, 'two dates selected: 1.1.2016, 2.2.2016; no times specified\nanswers: yes, no\nanonymous user: no\nforce answers: yes'); - - pollHasOptions(assert, [ - moment('2016-01-01').format( - moment.localeData().longDateFormat('LLLL') - .replace( - moment.localeData().longDateFormat('LT'), '') - .trim() - ), - moment('2016-02-02').format( - moment.localeData().longDateFormat('LLLL') - .replace( - moment.localeData().longDateFormat('LT'), '') - .trim() - ), - ]); - - assert.ok( - find('input', find('.newUserSelection')[0]).length, - 'answers are correct (count)' - ); - assert.ok( - find('.newUserSelection label .yes') && find('.newUserSelection label .no'), - 'answers are correct (class)' - ); - - pollHasAnswers(assert, ['Yes','No']); - - pollHasUsersCount(assert, 1); - pollHasUser(assert, 'Juri Gagarin', [Ember.I18n.t('answerTypes.yes.label'), Ember.I18n.t('answerTypes.no.label')]); - }); -}); - -test('show a poll (makeAPoll, freeText) created with v0.3.0', function(assert) { - var id = 'NLI7U2QEOE', - encryptionKey = 'tEig58l8DsEw8B629Kc544VvmegkYfbd1GozImKj'; - - server.get('/polls/' + id, function() { - return [ - 200, - { "Content-Type": "application/json" }, - '{"poll":{"encryptedTitle":"{\\"iv\\":\\"qPvy66kw9BDSGeMRE0kAVA==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"3eHLf1mM8Sbu8w6mPpQxoTVbo\\/z8myRMAemCYvCh+jA16myx2Oq5CHtVFBI+0v7jdWtBWHAU\\/xo=\\"}","encryptedDescription":"{\\"iv\\":\\"YTeSNaW622Jq5FP+ViYKqw==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"nxUebyFUKF6bnSyg6MRleJ4M8oHEtCIsiXFlZbXfTBt9Ryk7dNAAzDfTnJzdzxzTvUXHPCkHVP2rHhLq3CKgAkJDo1AmU2p4Qcc=\\"}","encryptedPollType":"{\\"iv\\":\\"nAsa8b4WuvoT4q5PrZ\\/APw==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"aysnMipL7WAAylWIcjeeOvovDQ==\\"}","encryptedAnswerType":"{\\"iv\\":\\"X\\/s19dp4Xx8FWfljx13n7A==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"iPBCoXKzCDwZqkUXAUGIeZLp\\"}","encryptedAnswers":"{\\"iv\\":\\"dkrELfNfFpXDItFEZdDPIw==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"XuDMfuNVnk0R7w==\\"}","encryptedOptions":"{\\"iv\\":\\"5Ta3GQeDl43b07eYnHjDyQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"d6oQ4wslFq80bxQZHF53sfiJyEZUYnJ4rNMQGsM03B+wug99ijQif9BGucMJ9bbNz8cD\\"}","encryptedCreationDate":"{\\"iv\\":\\"Hrh0aKUB3suiZurJksVExQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"BeGbWW55MXFKcshjmEWVCMGZ\\/5h1VF52LjLEQUGCBsyKWg==\\"}","encryptedForceAnswer":"{\\"iv\\":\\"84p+nSsIAOJHv\\/FprCsvDg==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"Y4o5JddmJ+4bq5Z2\\"}","encryptedAnonymousUser":"{\\"iv\\":\\"FwrZNpE05Dwk3Kwsd835vw==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"OacRpsJn7NhePn61Eg==\\"}","encryptedIsDateTime":"{\\"iv\\":\\"+8oX1bwIzPhhteIwH1Ce+w==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"tsv6mHV2vdziajjq3w==\\"}","encryptedTimezone":"{\\"iv\\":\\"ZY\\/UQmqSHQWUuVncuS3j\\/w==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"rnjPdsDJcbeciw==\\"}","version":"v0.3-0","id":"NLI7U2QEOE","users":[{"encryptedName":"{\\"iv\\":\\"\\/LdIkuVBjJBJRXYuJfyBlQ==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"rGsCm8TWuV4fjF1lDXaAmDmA79mx\\"}","encryptedSelections":"{\\"iv\\":\\"AfALavJ3clleK1ku63XC2A==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"6i77y3I8iZJkUuxJb+pc0a1zdSA3otK3d660cI9CCOpgmsZsQGkgq6x2XN9dSgdrMLrXAw==\\"}","encryptedCreationDate":"{\\"iv\\":\\"en9XKkmIub2ROGCc6RX9gg==\\",\\"v\\":1,\\"iter\\":1000,\\"ks\\":128,\\"ts\\":64,\\"mode\\":\\"ccm\\",\\"adata\\":\\"\\",\\"cipher\\":\\"aes\\",\\"salt\\":\\"Go+BZ2BlBbA=\\",\\"ct\\":\\"nZGqAHCtszEpX27WWL3trpJp1qzFnudGefSgnPXkMZ+xdQ==\\"}","version":"v0.3-0","poll":"NLI7U2QEOE","id":"0"}]}}' - ]; - }); - - visit('/poll/' + id + '?encryptionKey=' + encryptionKey); - - andThen(function() { - pollTitleEqual(assert, 'poll (makeAPoll, freeText) created with v0.3.0'); - pollDescriptionEqual(assert, 'poll type: makeAPoll\nanswer type: freeText\ncreated with v0.3.0'); - - pollHasOptions(assert, ['Option 1', 'Option 2']); - - pollHasUsersCount(assert, 1); - pollHasUser(assert, 'Georg Elser', ['Answer I', 'Answer II']); - }); -}); diff --git a/tests/dummyData/JlHpRs0Pzi/poll_data b/tests/dummyData/JlHpRs0Pzi/poll_data new file mode 100644 index 0000000..fec5ddd --- /dev/null +++ b/tests/dummyData/JlHpRs0Pzi/poll_data @@ -0,0 +1 @@ +{"poll":{"encryptedTitle":"{\"iv\":\"CyFXJkaPR8nHPxfZ3QzHKQ==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"z0VpAWbE9xa/NeIwpFNmFNvWDPAWyR+qafTWjlpE0K9B2kvRETpbO1q+\"}","encryptedDescription":"{\"iv\":\"fLP+ThbrPBgHZtKXR7OQZQ==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"x5693dRA11H2jt9rsb0IrT2Ys7AmF0eEmO0c9Qd6PAaU/VMU\"}","encryptedPollType":"{\"iv\":\"8i9uQL/a2p/wSPOrZVAWuA==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"FHfDWlVEgPVl6lbS3GyErLgEng==\"}","encryptedAnswerType":"{\"iv\":\"XGHKVaXBqOJKRjIz5YQ7yw==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"HnKzX+jpn2rO04Ujb/YEx6knzjY=\"}","encryptedAnswers":"{\"iv\":\"S3UKahavBtSR53oo43/0rg==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"47unEVJ1d3kd4iIMxQLRDYjXoDlZc5Dgl/Mn8CI6NxeMlD23P3yNpe8ho77H9ms3ciZGxqK4WgEn3DSALqmQWc9vM3SBk+zBfs0y+WMQJjeaC4n7DZ8ZvFihvOOGoq2IHUzkg7/Yuuld4YKYcPE8abOYKXr7qeZFkZLEEqC6vESSHnMp1J/S0Na0TiB9mqtNI+e+PvSso4K+IfHBYtk4lzMcjorsEkKJwhLENJ1M/7YaLnfAU7nWIAu5QmV5PPmTEshyR4Nwildba7FhLFmAXcM46T4s3bTAxjBkBUYJbpiehkFBj4fEKMlCXb748nlrn9NmJPPUwhLEQPW/a+0Ts1zlB2X8c0nmKWrsPJ3UahrUX/hFTyl4w9eC/9wgKjSXDbPDozZntt75bwPZ8hrZWY443nDn0UwO4xJ2dhfXxEtjf6jxpqAOtqEhQSveq/YZlaFs3wgbdXdbfObC\"}","encryptedOptions":"{\"iv\":\"H2Odh5d8xiV41Gmp5cNNEA==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"Cnm1bbdRSntawnkB0cxjAKlGGndzIKc2QyIFT/o4/JDZ/DGvBS2JMdh7nGjUG396SGvEMEWH/vApnkr6pvsyVH/j9PgIG51fGkKH+l1MqD/RsRulcEHKTDT5sBbyn4FlXoTvtYvohK9dQmJTx0KQGtK5uXYXJhWI\"}","encryptedCreationDate":"{\"iv\":\"FCtLmBGvQp3daBCDPOMeWA==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"R8htP6LflfZpWdKvWrFG+0tk/fO/Tane0x+Go7XJcf4FnQ==\"}","encryptedForceAnswer":"{\"iv\":\"h2Ry/duNbzOqYqfWL5FJtw==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"aRkdAO1OTcMSbWIz\"}","encryptedAnonymousUser":"{\"iv\":\"OfiX9GP1gi5oDUGsA/ffXg==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"GHCi6A0ve9XnC8scyw==\"}","encryptedIsDateTime":"{\"iv\":\"zsWI4NKCNlDniMQi2tI0Bg==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"OtTqPoepCqkdb3VZ\"}","encryptedTimezone":"{\"iv\":\"0SFZbfB+AuOrfgmwsOfPbQ==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"5D0biig/kbVJVOz8flj7yVt0Hk+HzjA=\"}","version":"v0.3-0"}} \ No newline at end of file diff --git a/tests/dummyData/JlHpRs0Pzi/user/0 b/tests/dummyData/JlHpRs0Pzi/user/0 new file mode 100644 index 0000000..0c9122c --- /dev/null +++ b/tests/dummyData/JlHpRs0Pzi/user/0 @@ -0,0 +1 @@ +{"user":{"encryptedName":"{\"iv\":\"R/cXZ6m3CHSsuO4CpDyb+Q==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"IwrPVCSqALv0as20uD8vfA0CgHtj\"}","encryptedSelections":"{\"iv\":\"6UONFgK1lipRlfPGhT669w==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"QD7mUdwuP65KUPJWZzY2Nj6Ebz8gzU5XNFAqU2YyaxENDQEG8tCedS6YoPATevunL8JmlLk99JU1WVr9YagAfwx1RqBC9RGoo8yrqtUgY4YhY8QS4euZUisUH1vHJo6UrxiehsJ3Gg457L1qs5d073wslfTIVpsT1FBQE4QejlNizxINGidTsKnNGyY/pfNhESvtVlyuQkzMMrQZr2V5gkcngqxnJL7Xr1QWT8IyxX7o8DCffO3IYHWzUprf+vFfxnKb91vWcuNHH4iIcnQqrcOEn2sEnuF8SK5G9pHMOl29yCKySUeq+snf+teLH3NE0jRkeb1ygeNYwRQa6WdD3bAh4r2RqRXmmvj/K+YZmPHwzYuIl5bgnBv5itfHBSbGOa7JnErXEp9qyUxw81Nev27EnDu+jJmurak7Ub05wUgVojuZodwutoxRT+Cv3LEn8ZhJsVs4+ujFiDG7OxyNfo4tGyqWGZbY60XKg5xOZA==\"}","encryptedCreationDate":"{\"iv\":\"fvMSYH7eGacN3pWZt79n1Q==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"lU+lEqixsqC3WAxYnrXsAFXRHpaG4l9j49CvAsmlvNEWTg==\"}","version":"v0.3-0","poll":"JlHpRs0Pzi"}} \ No newline at end of file diff --git a/tests/dummyData/JlHpRs0Pzi/user/1 b/tests/dummyData/JlHpRs0Pzi/user/1 new file mode 100644 index 0000000..cc469d2 --- /dev/null +++ b/tests/dummyData/JlHpRs0Pzi/user/1 @@ -0,0 +1 @@ +{"user":{"encryptedName":"{\"iv\":\"dJqDMtpybxd3Va0OWAz7dQ==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"q0EXDJx6OlJmk6GHSG095h6PCoy619ak\"}","encryptedSelections":"{\"iv\":\"3bMHwpqBVfNJddrzwLIe2Q==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"HHtQJievHhOf0tVY3GEGZIY36FNUlw67j9ZIvL/Tyfd2FghrwmPF+VMDrl8Rnr0x93JF+S9p5ZgXEC9GpuVT34S9kJY6dwaDkaSaORkVqXFTvXDEEMXwD0mA9FL6aDwYT25UY5OdEIYXpFkhiv0Hi+xtTvOJpxuq3FiOtgYxB4JU3JY53G20E2lPbVAOl89pnWT83eVNq/1dEd+SzVXR0J4pYNuuP7qrBJv+lN0c7456FL+32/NGo7e9UbLRYV++0UxIu10Jnc7A9VKRnGz/pghmX593DXG9NIHhCfvXu5t6zcMJp57NY6O+CAa5gSVzKw2Q80BJNgh3byjcvH+lqdu41/GONhqylVOc7RtPj0pqr4Up46gSe7tbHJA+84lWnwoIl9tSzgnwau0Fzxy3e+eDwSaHwhUiwOQGA4DJo9eCx7m/6Wj6u0yIOagKrP67S7HWoEiMVfBfPERiELhN2vsR4DSRDSDYA/gXkhu6N3LPnrhBwRdG6P+P\"}","encryptedCreationDate":"{\"iv\":\"nVUmPzlIuIdllptB865sIQ==\",\"v\":1,\"iter\":1000,\"ks\":128,\"ts\":64,\"mode\":\"ccm\",\"adata\":\"\",\"cipher\":\"aes\",\"salt\":\"mHJC65Kkl9c=\",\"ct\":\"FpW40CLc5nprDoyrGHGMx+B3tX/UHI+1+pLn2/R8kwJjdA==\"}","version":"v0.3-0","poll":"JlHpRs0Pzi"}} \ No newline at end of file diff --git a/tests/integration/legacy-support-test.js b/tests/integration/legacy-support-test.js new file mode 100644 index 0000000..a3f2239 --- /dev/null +++ b/tests/integration/legacy-support-test.js @@ -0,0 +1,74 @@ +import Ember from 'ember'; +import { module, test } from 'qunit'; +import startApp from 'croodle/tests/helpers/start-app'; +/* global moment */ + +var application; + +module('Integration | legacy support', { + beforeEach: function() { + application = startApp(); + }, + + afterEach: function() { + Ember.run(application, 'destroy'); + } +}); + +test('show a default poll created with v0.3.0', function(assert) { + var id = 'JlHpRs0Pzi', + encryptionKey = '5MKFuNTKILUXw6RuqkAw6ooZw4k3mWWx98ZQw8vH', + timezone = 'Europe/Berlin'; + + visit('/poll/' + id + '?encryptionKey=' + encryptionKey); + + andThen(function() { + pollTitleEqual(assert, 'default poll created with v0.3.0'); + pollDescriptionEqual(assert, 'used for integration tests'); + + pollHasOptionsDates(assert, [ + moment('2015-12-24').format( + moment.localeData().longDateFormat('LLLL') + .replace( + moment.localeData().longDateFormat('LT'), '') + .trim() + ), + moment('2015-12-31').format( + moment.localeData().longDateFormat('LLLL') + .replace( + moment.localeData().longDateFormat('LT'), '') + .trim() + ), + ]); + + pollHasOptionsTimes(assert, [ + moment.tz('2015-12-24T17:00:00.000Z', timezone).format('LT'), + moment.tz('2015-12-24T19:00:00.000Z', timezone).format('LT'), + moment.tz('2015-12-31T22:59:00.000Z', timezone).format('LT') + ]); + + pollHasAnswers(assert, [ + Ember.I18n.t('answerTypes.yes.label'), + Ember.I18n.t('answerTypes.maybe.label'), + Ember.I18n.t('answerTypes.no.label') + ]); + + pollHasUsersCount(assert, 2); + pollHasUser(assert, + 'Fritz Bauer', + [ + Ember.I18n.t('answerTypes.yes.label'), + Ember.I18n.t('answerTypes.no.label'), + Ember.I18n.t('answerTypes.no.label') + ] + ); + pollHasUser(assert, + 'Lothar Hermann', + [ + Ember.I18n.t('answerTypes.maybe.label'), + Ember.I18n.t('answerTypes.yes.label'), + Ember.I18n.t('answerTypes.no.label') + ] + ); + }); +});