From 402c534ee6453e28e5902f3d4f3a21b534309d24 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Thu, 18 Apr 2013 17:47:03 +0200 Subject: remove clientside hashing, fix #72 --- js/Gruntfile.coffee | 4 +- .../businesslayer/feedbusinesslayer.coffee | 10 +- js/app/services/models/feedmodel.coffee | 38 +-- js/config/testacular_conf.js | 1 - js/public/app.js | 56 ++- js/test-results.xml | 186 ++++++++++ .../businesslayer/feedbusinesslayerSpec.coffee | 68 ++-- .../businesslayer/folderbusinesslayerSpec.coffee | 30 +- .../businesslayer/itembusinesslayerSpec.coffee | 2 +- .../subsriptionsbusinesslayerSpec.coffee | 8 +- js/tests/services/models/feedmodelSpec.coffee | 44 +-- js/tests/services/models/itemmodelSpec.coffee | 2 +- js/vendor/md5js/md5.js | 379 --------------------- templates/main.php | 1 - templates/part.listfeed.php | 9 +- templates/part.listfolder.php | 10 +- 16 files changed, 320 insertions(+), 528 deletions(-) create mode 100644 js/test-results.xml delete mode 100644 js/vendor/md5js/md5.js diff --git a/js/Gruntfile.coffee b/js/Gruntfile.coffee index c12a5f322..02bb03d7d 100644 --- a/js/Gruntfile.coffee +++ b/js/Gruntfile.coffee @@ -66,8 +66,8 @@ module.exports = (grunt) -> src: '<%= meta.production %>app.js' dest: '' wrapper: [ - '(function(angular, $, hex_md5, moment, undefined){\n\n' - '\n})(window.angular, window.jQuery, window.hex_md5, window.moment);' + '(function(angular, $, moment, undefined){\n\n' + '\n})(window.angular, window.jQuery, window.moment);' ] coffeelint: diff --git a/js/app/services/businesslayer/feedbusinesslayer.coffee b/js/app/services/businesslayer/feedbusinesslayer.coffee index a5176452e..f02252618 100644 --- a/js/app/services/businesslayer/feedbusinesslayer.coffee +++ b/js/app/services/businesslayer/feedbusinesslayer.coffee @@ -92,7 +92,7 @@ FeedModel, NewLoading, _ExistsError, Utils) -> @_feedModel.update({ id: feedId, folderId: folderId, - urlHash: feed.urlHash}) + url: feed.url}) @_persistence.moveFeed(feedId, folderId) @@ -139,15 +139,13 @@ FeedModel, NewLoading, _ExistsError, Utils) -> throw new Error('Url must not be empty') url = url.trim() - urlHash = hex_md5(url) - if @_feedModel.getByUrlHash(urlHash) + if @_feedModel.getByUrl(url) throw new _ExistsError('Exists already') feed = title: url url: url - urlHash: urlHash folderId: parentId unreadCount: 0 faviconLink: 'url('+@_utils.imagePath('core', 'loading.gif')+')' @@ -164,8 +162,8 @@ FeedModel, NewLoading, _ExistsError, Utils) -> @_persistence.createFeed(url, parentId, success) - markErrorRead: (urlHash) -> - @_feedModel.removeByUrlHash(urlHash) + markErrorRead: (url) -> + @_feedModel.removeByUrl(url) updateFeeds: -> diff --git a/js/app/services/models/feedmodel.coffee b/js/app/services/models/feedmodel.coffee index feaeffee0..4c925b94c 100644 --- a/js/app/services/models/feedmodel.coffee +++ b/js/app/services/models/feedmodel.coffee @@ -27,12 +27,12 @@ angular.module('News').factory 'FeedModel', class FeedModel extends _Model constructor: (@_utils) -> - @_urlHash = {} + @_url = {} super() clear: -> - @_urlHash = {} + @_url = {} super() @@ -48,7 +48,7 @@ angular.module('News').factory 'FeedModel', an id, we have to update the existing item without id ### - item = @_urlHash[data.urlHash] + item = @_url[data.url] # update in the following cases: # * the id is defined and the item exists @@ -56,15 +56,15 @@ angular.module('News').factory 'FeedModel', updateById = angular.isDefined(data.id) and angular.isDefined(@getById(data.id)) - updateByUrlHash = angular.isDefined(item) and + updateByUrl = angular.isDefined(item) and angular.isUndefined(item.id) - if updateById or updateByUrlHash + if updateById or updateByUrl @update(data, clearCache) else - if angular.isDefined(data.urlHash) + if angular.isDefined(data.url) # if the item is not yet in the name cache it must be added - @_urlHash[data.urlHash] = data + @_url[data.url] = data # in case there is an id it can go through the normal add method if angular.isDefined(data.id) @@ -80,8 +80,8 @@ angular.module('News').factory 'FeedModel', update: (data, clearCache=true) -> # only when the id on the updated item does not exist we wish # to update by name, otherwise we always update by id - if angular.isDefined(data.urlHash) - item = @_urlHash[data.urlHash] + if angular.isDefined(data.url) + item = @_url[data.url] # update by name if angular.isUndefined(data.id) and angular.isDefined(item) @@ -100,21 +100,21 @@ angular.module('News').factory 'FeedModel', # we need to fix the name cache if the name was changed itemWithId = @getById(data.id) if angular.isDefined(itemWithId) and - itemWithId.urlHash != data.urlHash - delete @_urlHash[itemWithId.urlHash] - @_urlHash[data.urlHash] = itemWithId + itemWithId.url != data.url + delete @_url[itemWithId.url] + @_url[data.url] = itemWithId super(data, clearCache) removeById: (id) -> item = @getById(id) - delete @_urlHash[item.urlHash] + delete @_url[item.url] super(id) - getByUrlHash: (urlHash) -> - return @_urlHash[urlHash] + getByUrl: (url) -> + return @_url[url] getUnreadCount: -> @@ -148,21 +148,21 @@ angular.module('News').factory 'FeedModel', return @get(query) - removeByUrlHash: (urlHash, clearCache=true) -> + removeByUrl: (url, clearCache=true) -> ### Remove an entry by id ### # remove from data map for key, value of @_dataMap - if @_dataMap[key].urlHash == urlHash + if @_dataMap[key].url == url delete @_dataMap[key] break for entry, counter in @_data - if entry.urlHash == urlHash + if entry.url == url @_data.splice(counter, 1) - delete @_urlHash[urlHash] + delete @_url[url] if clearCache @_invalidateCache() diff --git a/js/config/testacular_conf.js b/js/config/testacular_conf.js index 17c654805..d5cb87ba0 100644 --- a/js/config/testacular_conf.js +++ b/js/config/testacular_conf.js @@ -36,7 +36,6 @@ files = [ 'vendor/angular/angular.js', 'vendor/angular/angular-mocks.js', 'vendor/angular-ui/angular-ui.js', - 'vendor/md5js/md5.js', 'vendor/momentjs/moment.js', '../../appframework/js/tests/stubs/owncloud.js', '../../appframework/js/public/app.js', diff --git a/js/public/app.js b/js/public/app.js index 7e4393d94..855bcd895 100644 --- a/js/public/app.js +++ b/js/public/app.js @@ -1,4 +1,4 @@ -(function(angular, $, hex_md5, moment, undefined){ +(function(angular, $, moment, undefined){ /** * ownCloud News App - v0.0.1 @@ -794,7 +794,7 @@ License along with this library. If not, see . this._feedModel.update({ id: feedId, folderId: folderId, - urlHash: feed.urlHash + url: feed.url }); return this._persistence.moveFeed(feedId, folderId); } @@ -837,7 +837,7 @@ License along with this library. If not, see . }; FeedBusinessLayer.prototype.create = function(url, parentId, onSuccess, onFailure) { - var feed, success, urlHash, + var feed, success, _this = this; if (parentId == null) { @@ -856,14 +856,12 @@ License along with this library. If not, see . throw new Error('Url must not be empty'); } url = url.trim(); - urlHash = hex_md5(url); - if (this._feedModel.getByUrlHash(urlHash)) { + if (this._feedModel.getByUrl(url)) { throw new _ExistsError('Exists already'); } feed = { title: url, url: url, - urlHash: urlHash, folderId: parentId, unreadCount: 0, faviconLink: 'url(' + this._utils.imagePath('core', 'loading.gif') + ')' @@ -880,8 +878,8 @@ License along with this library. If not, see . return this._persistence.createFeed(url, parentId, success); }; - FeedBusinessLayer.prototype.markErrorRead = function(urlHash) { - return this._feedModel.removeByUrlHash(urlHash); + FeedBusinessLayer.prototype.markErrorRead = function(url) { + return this._feedModel.removeByUrl(url); }; FeedBusinessLayer.prototype.updateFeeds = function() { @@ -1598,17 +1596,17 @@ License along with this library. If not, see . function FeedModel(_utils) { this._utils = _utils; - this._urlHash = {}; + this._url = {}; FeedModel.__super__.constructor.call(this); } FeedModel.prototype.clear = function() { - this._urlHash = {}; + this._url = {}; return FeedModel.__super__.clear.call(this); }; FeedModel.prototype.add = function(data, clearCache) { - var item, updateById, updateByUrlHash; + var item, updateById, updateByUrl; if (clearCache == null) { clearCache = true; @@ -1624,14 +1622,14 @@ License along with this library. If not, see . an id, we have to update the existing item without id */ - item = this._urlHash[data.urlHash]; + item = this._url[data.url]; updateById = angular.isDefined(data.id) && angular.isDefined(this.getById(data.id)); - updateByUrlHash = angular.isDefined(item) && angular.isUndefined(item.id); - if (updateById || updateByUrlHash) { + updateByUrl = angular.isDefined(item) && angular.isUndefined(item.id); + if (updateById || updateByUrl) { return this.update(data, clearCache); } else { - if (angular.isDefined(data.urlHash)) { - this._urlHash[data.urlHash] = data; + if (angular.isDefined(data.url)) { + this._url[data.url] = data; if (angular.isDefined(data.id)) { return FeedModel.__super__.add.call(this, data, clearCache); } else { @@ -1650,8 +1648,8 @@ License along with this library. If not, see . if (clearCache == null) { clearCache = true; } - if (angular.isDefined(data.urlHash)) { - item = this._urlHash[data.urlHash]; + if (angular.isDefined(data.url)) { + item = this._url[data.url]; } if (angular.isUndefined(data.id) && angular.isDefined(item)) { return angular.extend(item, data); @@ -1661,9 +1659,9 @@ License along with this library. If not, see . this._dataMap[data.id] = item; } itemWithId = this.getById(data.id); - if (angular.isDefined(itemWithId) && itemWithId.urlHash !== data.urlHash) { - delete this._urlHash[itemWithId.urlHash]; - this._urlHash[data.urlHash] = itemWithId; + if (angular.isDefined(itemWithId) && itemWithId.url !== data.url) { + delete this._url[itemWithId.url]; + this._url[data.url] = itemWithId; } return FeedModel.__super__.update.call(this, data, clearCache); } @@ -1673,12 +1671,12 @@ License along with this library. If not, see . var item; item = this.getById(id); - delete this._urlHash[item.urlHash]; + delete this._url[item.url]; return FeedModel.__super__.removeById.call(this, id); }; - FeedModel.prototype.getByUrlHash = function(urlHash) { - return this._urlHash[urlHash]; + FeedModel.prototype.getByUrl = function(url) { + return this._url[url]; }; FeedModel.prototype.getUnreadCount = function() { @@ -1725,7 +1723,7 @@ License along with this library. If not, see . return this.get(query); }; - FeedModel.prototype.removeByUrlHash = function(urlHash, clearCache) { + FeedModel.prototype.removeByUrl = function(url, clearCache) { var counter, entry, key, value, _i, _len, _ref, _ref1, _results; if (clearCache == null) { @@ -1738,7 +1736,7 @@ License along with this library. If not, see . _ref = this._dataMap; for (key in _ref) { value = _ref[key]; - if (this._dataMap[key].urlHash === urlHash) { + if (this._dataMap[key].url === url) { delete this._dataMap[key]; break; } @@ -1747,9 +1745,9 @@ License along with this library. If not, see . _results = []; for (counter = _i = 0, _len = _ref1.length; _i < _len; counter = ++_i) { entry = _ref1[counter]; - if (entry.urlHash === urlHash) { + if (entry.url === url) { this._data.splice(counter, 1); - delete this._urlHash[urlHash]; + delete this._url[url]; if (clearCache) { this._invalidateCache(); } @@ -2977,4 +2975,4 @@ License along with this library. If not, see . }).call(this); -})(window.angular, window.jQuery, window.hex_md5, window.moment); \ No newline at end of file +})(window.angular, window.jQuery, window.moment); \ No newline at end of file diff --git a/js/test-results.xml b/js/test-results.xml new file mode 100644 index 000000000..c6fcaac7d --- /dev/null +++ b/js/test-results.xml @@ -0,0 +1,186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee index 1b9f009d5..f867443c7 100644 --- a/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/feedbusinesslayerSpec.coffee @@ -58,16 +58,16 @@ describe 'FeedBusinessLayer', -> it 'should return the number of unread feeds', => - @FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'}) + @FeedModel.add({id: 3, unreadCount:134, url: 'a1'}) count = @FeedBusinessLayer.getUnreadCount(3) expect(count).toBe(134) it 'should return all feeds of a folder', => - feed1 = {id: 3, unreadCount:134, urlHash: 'a1', folderId: 3} - feed2 = {id: 4, unreadCount:134, urlHash: 'a2', folderId: 2} - feed3 = {id: 5, unreadCount:134, urlHash: 'a3', folderId: 3} + feed1 = {id: 3, unreadCount:134, url: 'a1', folderId: 3} + feed2 = {id: 4, unreadCount:134, url: 'a2', folderId: 2} + feed3 = {id: 5, unreadCount:134, url: 'a3', folderId: 3} @FeedModel.add(feed1) @FeedModel.add(feed2) @FeedModel.add(feed3) @@ -79,10 +79,10 @@ describe 'FeedBusinessLayer', -> it 'should get the correct unread count for folders', => - @FeedModel.add({id: 3, unreadCount:134, folderId: 3, urlHash: 'a1'}) - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a2'}) - @FeedModel.add({id: 1, unreadCount:12, folderId: 5, urlHash: 'a3'}) - @FeedModel.add({id: 2, unreadCount:35, folderId: 3, urlHash: 'a4'}) + @FeedModel.add({id: 3, unreadCount:134, folderId: 3, url: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a2'}) + @FeedModel.add({id: 1, unreadCount:12, folderId: 5, url: 'a3'}) + @FeedModel.add({id: 2, unreadCount:35, folderId: 3, url: 'a4'}) count = @FeedBusinessLayer.getFolderUnreadCount(3) expect(count).toBe(169) @@ -91,7 +91,7 @@ describe 'FeedBusinessLayer', -> it 'should mark feed as read', => @ActiveFeed.handle({type: @FeedType.Feed, id: 5}) @persistence.setFeedRead = jasmine.createSpy('setFeedRead') - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a1'}) @ItemModel.add({id: 6, feedId: 5, guidHash: 'a1'}) @ItemModel.add({id: 3, feedId: 5, guidHash: 'a2'}) @ItemModel.add({id: 2, feedId: 5, guidHash: 'a3'}) @@ -106,7 +106,7 @@ describe 'FeedBusinessLayer', -> it 'should mark feed as read and set 0 if as highest id if its not active',=> @persistence.setFeedRead = jasmine.createSpy('setFeedRead') - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a1'}) @ItemModel.add({id: 6, feedId: 5, guidHash: 'a1'}) @ItemModel.add({id: 3, feedId: 5, guidHash: 'a2'}) @ItemModel.add({id: 2, feedId: 5, guidHash: 'a3'}) @@ -121,9 +121,9 @@ describe 'FeedBusinessLayer', -> it 'should mark all as read', => @persistence.setFeedRead = jasmine.createSpy('setFeedRead') - @FeedModel.add({id: 3, unreadCount:134, folderId: 3, urlHash: 'a1'}) - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a2'}) - @FeedModel.add({id: 1, unreadCount:12, folderId: 3, urlHash: 'a3'}) + @FeedModel.add({id: 3, unreadCount:134, folderId: 3, url: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a2'}) + @FeedModel.add({id: 1, unreadCount:12, folderId: 3, url: 'a3'}) @FeedBusinessLayer.markAllRead() @@ -133,16 +133,16 @@ describe 'FeedBusinessLayer', -> it 'should get the correct unread count for subscribtions', => - @FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'}) - @FeedModel.add({id: 5, unreadCount:2, urlHash: 'a2'}) + @FeedModel.add({id: 3, unreadCount:134, url: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, url: 'a2'}) count = @FeedBusinessLayer.getAllUnreadCount() expect(count).toBe(136) it 'should return the correct number of feeds', => - @FeedModel.add({id: 3, unreadCount:134, urlHash: 'a1'}) - @FeedModel.add({id: 5, unreadCount:2, urlHash: 'a2'}) + @FeedModel.add({id: 3, unreadCount:134, url: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, url: 'a2'}) count = @FeedBusinessLayer.getNumberOfFeeds() expect(count).toBe(2) @@ -161,13 +161,13 @@ describe 'FeedBusinessLayer', -> it 'should be visible if unreadcount bigger than 0', => - @FeedModel.add({id: 2, unreadCount:134, urlHash: 'a1'}) + @FeedModel.add({id: 2, unreadCount:134, url: 'a1'}) expect(@FeedBusinessLayer.isVisible(2)).toBe(true) it 'should not move the feed to a new folder', => @persistence.moveFeed = jasmine.createSpy('Move feed') - @FeedModel.add({id: 2, unreadCount:134, urlHash: 'a1', folderId: 3}) + @FeedModel.add({id: 2, unreadCount:134, url: 'a1', folderId: 3}) @FeedBusinessLayer.move(2, 4) expect(@persistence.moveFeed).toHaveBeenCalledWith(2, 4) @@ -176,7 +176,7 @@ describe 'FeedBusinessLayer', -> it 'should not move the feed to the same folder', => @persistence.moveFeed = jasmine.createSpy('Move feed') - @FeedModel.add({id: 2, unreadCount:134, urlHash: 'a1', folderId: 3}) + @FeedModel.add({id: 2, unreadCount:134, url: 'a1', folderId: 3}) @FeedBusinessLayer.move(2, 3) expect(@persistence.moveFeed).not.toHaveBeenCalled() @@ -198,8 +198,8 @@ describe 'FeedBusinessLayer', -> it 'should return all feeds', => - item1 = {id: 2, unreadCount:134, urlHash: 'a1', folderId: 3} - item2 = {id: 4, unreadCount:134, urlHash: 'a2', folderId: 3} + item1 = {id: 2, unreadCount:134, url: 'a1', folderId: 3} + item2 = {id: 4, unreadCount:134, url: 'a2', folderId: 3} @FeedModel.add(item1) @FeedModel.add(item2) @@ -216,9 +216,9 @@ describe 'FeedBusinessLayer', -> it 'should return all feeds of a folder', => - item1 = {id: 2, unreadCount:134, urlHash: 'a1', folderId: 3} - item2 = {id: 4, unreadCount:134, urlHash: 'a2', folderId: 2} - item3 = {id: 5, unreadCount:134, urlHash: 'a3', folderId: 3} + item1 = {id: 2, unreadCount:134, url: 'a1', folderId: 3} + item2 = {id: 4, unreadCount:134, url: 'a2', folderId: 2} + item3 = {id: 5, unreadCount:134, url: 'a3', folderId: 3} @FeedModel.add(item1) @FeedModel.add(item2) @FeedModel.add(item3) @@ -233,7 +233,7 @@ describe 'FeedBusinessLayer', -> item2 = id: 4, unreadCount:134, - urlHash: 'a2', + url: 'a2', folderId: 3, link: 'test.com' @FeedModel.add(item2) @@ -243,7 +243,7 @@ describe 'FeedBusinessLayer', -> it 'should not create a feed if it already exists', => - item1 = {urlHash: hex_md5('john')} + item1 = {url: 'john'} @FeedModel.add(item1) expect => @@ -269,13 +269,11 @@ describe 'FeedBusinessLayer', -> it 'should set a title and an url hash to the newly crated feed', => url = 'www.google.de' @FeedBusinessLayer.create(url) - hash = hex_md5(url) - feed = @FeedModel.getByUrlHash(hash) + feed = @FeedModel.getByUrl(url) expect(feed.title).toBe('www.google.de') expect(feed.url).toBe(url) - expect(feed.urlHash).toBe(hash) expect(feed.folderId).toBe(0) expect(feed.unreadCount).toBe(0) expect(@imagePath).toHaveBeenCalledWith('core', 'loading.gif') @@ -318,22 +316,22 @@ describe 'FeedBusinessLayer', -> expect(onSuccess).not.toHaveBeenCalled() expect(onFailure).toHaveBeenCalled() - expect(@FeedModel.getByUrlHash(hex_md5('johns')).error).toBe( + expect(@FeedModel.getByUrl('johns').error).toBe( @response.msg) it 'should mark a feed error as read by removing it', => - @FeedModel.add({id: 3, urlHash: 'john'}) + @FeedModel.add({id: 3, url: 'john'}) @FeedBusinessLayer.markErrorRead('john') expect(@FeedModel.size()).toBe(0) - expect(@FeedModel.getByUrlHash('john')).toBe(undefined) + expect(@FeedModel.getByUrl('john')).toBe(undefined) it 'should update all feeds', => @persistence.updateFeed = jasmine.createSpy('update') - @FeedModel.add({id: 3, urlHash: 'john'}) + @FeedModel.add({id: 3, url: 'john'}) @FeedBusinessLayer.updateFeeds() @@ -342,7 +340,7 @@ describe 'FeedBusinessLayer', -> it 'should not update feeds without ids', => @persistence.updateFeed = jasmine.createSpy('update') - @FeedModel.add({urlHash: 'john'}) + @FeedModel.add({url: 'john'}) @FeedBusinessLayer.updateFeeds() diff --git a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee index a4cb80162..f0241979f 100644 --- a/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/folderbusinesslayerSpec.coffee @@ -54,10 +54,10 @@ describe 'FolderBusinessLayer', -> it 'should return true when folder has feeds', => - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a1'}) expect(@FolderBusinessLayer.hasFeeds(3)).toBeFalsy() - @FeedModel.add({id: 2, unreadCount:35, folderId: 3, urlHash: 'a2'}) + @FeedModel.add({id: 2, unreadCount:35, folderId: 3, url: 'a2'}) expect(@FolderBusinessLayer.hasFeeds(3)).toBeTruthy() @@ -80,9 +80,9 @@ describe 'FolderBusinessLayer', -> it 'should mark folder as read', => @persistence.setFeedRead = jasmine.createSpy('setFeedRead') - @FeedModel.add({id: 3, unreadCount:134, folderId: 3, urlHash: 'a1'}) - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a2'}) - @FeedModel.add({id: 1, unreadCount:12, folderId: 3, urlHash: 'a3'}) + @FeedModel.add({id: 3, unreadCount:134, folderId: 3, url: 'a1'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a2'}) + @FeedModel.add({id: 1, unreadCount:12, folderId: 3, url: 'a3'}) @FolderBusinessLayer.markFolderRead(3) @@ -92,9 +92,9 @@ describe 'FolderBusinessLayer', -> it 'should get the correct unread count', => - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'}) - @FeedModel.add({id: 6, unreadCount:3, folderId: 3, urlHash: 'a2'}) - @FeedModel.add({id: 7, unreadCount:4, folderId: 2, urlHash: 'a3'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a1'}) + @FeedModel.add({id: 6, unreadCount:3, folderId: 3, url: 'a2'}) + @FeedModel.add({id: 7, unreadCount:4, folderId: 2, url: 'a3'}) expect(@FolderBusinessLayer.getUnreadCount(2)).toBe(6) @@ -112,18 +112,18 @@ describe 'FolderBusinessLayer', -> it 'should be visible if one of its subfeeds is active', => - @FeedModel.add({id: 5, unreadCount:0, folderId: 2, urlHash: 'a1'}) - @FeedModel.add({id: 6, unreadCount:0, folderId: 3, urlHash: 'a2'}) - @FeedModel.add({id: 7, unreadCount:0, folderId: 2, urlHash: 'a3'}) + @FeedModel.add({id: 5, unreadCount:0, folderId: 2, url: 'a1'}) + @FeedModel.add({id: 6, unreadCount:0, folderId: 3, url: 'a2'}) + @FeedModel.add({id: 7, unreadCount:0, folderId: 2, url: 'a3'}) @ActiveFeed.handle({type: @FeedType.Feed, id:6}) expect(@FolderBusinessLayer.isVisible(3)).toBe(true) it 'should be visible if showAll is false and it has unread items', => - @FeedModel.add({id: 5, unreadCount:2, folderId: 2, urlHash: 'a1'}) - @FeedModel.add({id: 6, unreadCount:3, folderId: 3, urlHash: 'a2'}) - @FeedModel.add({id: 7, unreadCount:4, folderId: 2, urlHash: 'a3'}) + @FeedModel.add({id: 5, unreadCount:2, folderId: 2, url: 'a1'}) + @FeedModel.add({id: 6, unreadCount:3, folderId: 3, url: 'a2'}) + @FeedModel.add({id: 7, unreadCount:4, folderId: 2, url: 'a3'}) @ActiveFeed.handle({type: @FeedType.Folder, id:2}) expect(@FolderBusinessLayer.isVisible(3)).toBe(true) @@ -415,7 +415,7 @@ describe 'FolderBusinessLayer', -> @persistence.createFolder = jasmine.createSpy('create folder') @persistence.createFeed = jasmine.createSpy('create feed') - @FeedModel.add({urlHash: hex_md5('http://worrydream.com/feed.xml')}) + @FeedModel.add({url: 'http://worrydream.com/feed.xml'}) xml = ' diff --git a/js/tests/services/businesslayer/itembusinesslayerSpec.coffee b/js/tests/services/businesslayer/itembusinesslayerSpec.coffee index 5f4744ffa..0b8358f2a 100644 --- a/js/tests/services/businesslayer/itembusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/itembusinesslayerSpec.coffee @@ -33,7 +33,7 @@ describe 'ItemBusinessLayer', -> beforeEach inject (@ItemModel, @ItemBusinessLayer, @StatusFlag, @ActiveFeed @FeedType, @FeedModel, @StarredBusinessLayer) => - @item1 = {id: 5, title: 'hi', unreadCount:134, urlHash: 'a3', folderId: 3} + @item1 = {id: 5, title: 'hi', unreadCount:134, url: 'a3', folderId: 3} @FeedModel.add(@item1) @ActiveFeed.handle({type: @FeedType.Feed, id: 3}) diff --git a/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee b/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee index 48ae9e03c..090433fbd 100644 --- a/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee +++ b/js/tests/services/businesslayer/subsriptionsbusinesslayerSpec.coffee @@ -40,7 +40,7 @@ describe 'SubscriptionsBusinessLayer', -> it 'should be visible shows all items is set to true and there are feeds', => - @FeedModel.add({id: 3, unreadCount: 5, urlHash: 'hi'}) + @FeedModel.add({id: 3, unreadCount: 5, url: 'hi'}) expect(@SubscriptionsBusinessLayer.isVisible()).toBe(true) @@ -66,7 +66,7 @@ describe 'SubscriptionsBusinessLayer', -> it 'should mark all feeds as read', => - item = {id: 3, unreadCount: 132, urlHash: 'hi'} + item = {id: 3, unreadCount: 132, url: 'hi'} @FeedModel.add(item) @SubscriptionsBusinessLayer.markAllRead() @@ -76,8 +76,8 @@ describe 'SubscriptionsBusinessLayer', -> it 'should get the correct unread count', => - @FeedModel.add({id: 3, unreadCount: 132, urlHash: 'hoho'}) - @FeedModel.add({id: 4, unreadCount: 12, urlHash: 'hohod'}) + @FeedModel.add({id: 3, unreadCount: 132, url: 'hoho'}) + @FeedModel.add({id: 4, unreadCount: 12, url: 'hohod'}) expect(@SubscriptionsBusinessLayer.getUnreadCount()).toBe(144) diff --git a/js/tests/services/models/feedmodelSpec.coffee b/js/tests/services/models/feedmodelSpec.coffee index 6b6eb85f6..082e1aa32 100644 --- a/js/tests/services/models/feedmodelSpec.coffee +++ b/js/tests/services/models/feedmodelSpec.coffee @@ -45,7 +45,7 @@ describe 'FeedModel', -> item = id: 3 faviconLink: null - urlHash: 'hi' + url: 'hi' @FeedModel.add(item) @@ -53,82 +53,82 @@ describe 'FeedModel', -> it 'should add feeds without id', => - item = {faviconLink: null, urlHash: 'hi'} + item = {faviconLink: null, url: 'hi'} @FeedModel.add(item) - item2 = {faviconLink: null, urlHash: 'his'} + item2 = {faviconLink: null, url: 'his'} @FeedModel.add(item2) - expect(@FeedModel.getByUrlHash('hi')).toBe(item) + expect(@FeedModel.getByUrl('hi')).toBe(item) expect(@FeedModel.size()).toBe(2) - it 'should clear the url hash cache', => - item = {faviconLink: null, urlHash: 'hi'} + it 'should clear the url cache', => + item = {faviconLink: null, url: 'hi'} @FeedModel.add(item) @FeedModel.clear() - expect(@FeedModel.getByUrlHash('hi')).toBe(undefined) + expect(@FeedModel.getByUrl('hi')).toBe(undefined) expect(@FeedModel.size()).toBe(0) it 'should delete items from the fodername cache', => - item = {id:3, faviconLink: null, urlHash: 'hi'} + item = {id:3, faviconLink: null, url: 'hi'} @FeedModel.add(item) expect(@FeedModel.size()).toBe(1) @FeedModel.removeById(3) - expect(@FeedModel.getByUrlHash('hi')).toBe(undefined) + expect(@FeedModel.getByUrl('hi')).toBe(undefined) expect(@FeedModel.size()).toBe(0) it 'should update the id if an update comes in with an id', => - item = {faviconLink: null, urlHash: 'hi', test: 'heheh'} + item = {faviconLink: null, url: 'hi', test: 'heheh'} @FeedModel.add(item) - item2 = {id: 3, faviconLink: null, urlHash: 'hi', test: 'hoho'} + item2 = {id: 3, faviconLink: null, url: 'hi', test: 'hoho'} @FeedModel.add(item2) - expect(@FeedModel.getByUrlHash('hi').id).toBe(3) - expect(@FeedModel.getByUrlHash('hi').test).toBe('hoho') + expect(@FeedModel.getByUrl('hi').id).toBe(3) + expect(@FeedModel.getByUrl('hi').test).toBe('hoho') expect(@FeedModel.getById(3).id).toBe(3) expect(@FeedModel.getById(3).test).toBe('hoho') expect(@FeedModel.size()).toBe(1) it 'should update normally', => - item = {id: 3, faviconLink: null, urlHash: 'hi', test: 'heheh'} + item = {id: 3, faviconLink: null, url: 'hi', test: 'heheh'} @FeedModel.add(item) - item2 = {id: 3, faviconLink: null, urlHash: 'his', test: 'hoho'} + item2 = {id: 3, faviconLink: null, url: 'his', test: 'hoho'} @FeedModel.add(item2) - expect(@FeedModel.getByUrlHash('hi')).toBe(undefined) - expect(@FeedModel.getByUrlHash('his').id).toBe(3) - expect(@FeedModel.getByUrlHash('his').test).toBe('hoho') + expect(@FeedModel.getByUrl('hi')).toBe(undefined) + expect(@FeedModel.getByUrl('his').id).toBe(3) + expect(@FeedModel.getByUrl('his').test).toBe('hoho') expect(@FeedModel.getById(3).test).toBe('hoho') expect(@FeedModel.size()).toBe(1) it 'should clear invalidate the query cache on adding folder with name', => - item = {faviconLink: null, urlHash: 'hi', test: 'heheh', folderId: 0} + item = {faviconLink: null, url: 'hi', test: 'heheh', folderId: 0} expect(@FeedModel.getAllOfFolder(0).length).toBe(0) @FeedModel.add(item, false) expect(@FeedModel.getAllOfFolder(0).length).toBe(0) - item2 = {faviconLink: null, urlHash: 'his', test: 'heheh', folderId: 0} + item2 = {faviconLink: null, url: 'his', test: 'heheh', folderId: 0} @FeedModel.add(item2) expect(@FeedModel.getAllOfFolder(0).length).toBe(2) - it 'should only update feeds that contain only an id but no url hash', => + it 'should only update feeds that contain only an id but no url', => item = {id: 3, unreadCount: 232} @FeedModel.add(item) expect(@FeedModel.size()).toBe(0) - item2 = {id: 3, unreadCount: 2, faviconLink: null, urlHash: 'his'} + item2 = {id: 3, unreadCount: 2, faviconLink: null, url: 'his'} @FeedModel.add(item2) @FeedModel.add(item) diff --git a/js/tests/services/models/itemmodelSpec.coffee b/js/tests/services/models/itemmodelSpec.coffee index 4e93609ea..2171f12ea 100644 --- a/js/tests/services/models/itemmodelSpec.coffee +++ b/js/tests/services/models/itemmodelSpec.coffee @@ -57,7 +57,7 @@ describe 'ItemModel', -> expect(@ItemModel.size()).toBe(2) - it 'should also remove the feed from the urlHash cache when its removed', => + it 'should also remove the feed from the url cache when its removed', => item = {id: 4, guidHash: 'abc', feedId: 3} @ItemModel.add(item) diff --git a/js/vendor/md5js/md5.js b/js/vendor/md5js/md5.js deleted file mode 100644 index a8cc0eee8..000000000 --- a/js/vendor/md5js/md5.js +++ /dev/null @@ -1,379 +0,0 @@ -/* - * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message - * Digest Algorithm, as defined in RFC 1321. - * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for more info. - */ - -/* - * Configurable variables. You may need to tweak these to be compatible with - * the server-side, but the defaults work in most cases. - */ -var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ -var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */ - -/* - * These are the functions you'll usually want to call - * They take string arguments and return either hex or base-64 encoded strings - */ -function hex_md5(s) { return rstr2hex(rstr_md5(str2rstr_utf8(s))); } -function b64_md5(s) { return rstr2b64(rstr_md5(str2rstr_utf8(s))); } -function any_md5(s, e) { return rstr2any(rstr_md5(str2rstr_utf8(s)), e); } -function hex_hmac_md5(k, d) - { return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } -function b64_hmac_md5(k, d) - { return rstr2b64(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d))); } -function any_hmac_md5(k, d, e) - { return rstr2any(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)), e); } - -/* - * Perform a simple self-test to see if the VM is working - */ -function md5_vm_test() -{ - return hex_md5("abc").toLowerCase() == "900150983cd24fb0d6963f7d28e17f72"; -} - -/* - * Calculate the MD5 of a raw string - */ -function rstr_md5(s) -{ - return binl2rstr(binl_md5(rstr2binl(s), s.length * 8)); -} - -/* - * Calculate the HMAC-MD5, of a key and some data (raw strings) - */ -function rstr_hmac_md5(key, data) -{ - var bkey = rstr2binl(key); - if(bkey.length > 16) bkey = binl_md5(bkey, key.length * 8); - - var ipad = Array(16), opad = Array(16); - for(var i = 0; i < 16; i++) - { - ipad[i] = bkey[i] ^ 0x36363636; - opad[i] = bkey[i] ^ 0x5C5C5C5C; - } - - var hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8); - return binl2rstr(binl_md5(opad.concat(hash), 512 + 128)); -} - -/* - * Convert a raw string to a hex string - */ -function rstr2hex(input) -{ - try { hexcase } catch(e) { hexcase=0; } - var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; - var output = ""; - var x; - for(var i = 0; i < input.length; i++) - { - x = input.charCodeAt(i); - output += hex_tab.charAt((x >>> 4) & 0x0F) - + hex_tab.charAt( x & 0x0F); - } - return output; -} - -/* - * Convert a raw string to a base-64 string - */ -function rstr2b64(input) -{ - try { b64pad } catch(e) { b64pad=''; } - var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - var output = ""; - var len = input.length; - for(var i = 0; i < len; i += 3) - { - var triplet = (input.charCodeAt(i) << 16) - | (i + 1 < len ? input.charCodeAt(i+1) << 8 : 0) - | (i + 2 < len ? input.charCodeAt(i+2) : 0); - for(var j = 0; j < 4; j++) - { - if(i * 8 + j * 6 > input.length * 8) output += b64pad; - else output += tab.charAt((triplet >>> 6*(3-j)) & 0x3F); - } - } - return output; -} - -/* - * Convert a raw string to an arbitrary string encoding - */ -function rstr2any(input, encoding) -{ - var divisor = encoding.length; - var i, j, q, x, quotient; - - /* Convert to an array of 16-bit big-endian values, forming the dividend */ - var dividend = Array(Math.ceil(input.length / 2)); - for(i = 0; i < dividend.length; i++) - { - dividend[i] = (input.charCodeAt(i * 2) << 8) | input.charCodeAt(i * 2 + 1); - } - - /* - * Repeatedly perform a long division. The binary array forms the dividend, - * the length of the encoding is the divisor. Once computed, the quotient - * forms the dividend for the next step. All remainders are stored for later - * use. - */ - var full_length = Math.ceil(input.length * 8 / - (Math.log(encoding.length) / Math.log(2))); - var remainders = Array(full_length); - for(j = 0; j < full_length; j++) - { - quotient = Array(); - x = 0; - for(i = 0; i < dividend.length; i++) - { - x = (x << 16) + dividend[i]; - q = Math.floor(x / divisor); - x -= q * divisor; - if(quotient.length > 0 || q > 0) - quotient[quotient.length] = q; - } - remainders[j] = x; - dividend = quotient; - } - - /* Convert the remainders to the output string */ - var output = ""; - for(i = remainders.length - 1; i >= 0; i--) - output += encoding.charAt(remainders[i]); - - return output; -} - -/* - * Encode a string as utf-8. - * For efficiency, this assumes the input is valid utf-16. - */ -function str2rstr_utf8(input) -{ - var output = ""; - var i = -1; - var x, y; - - while(++i < input.length) - { - /* Decode utf-16 surrogate pairs */ - x = input.charCodeAt(i); - y = i + 1 < input.length ? input.charCodeAt(i + 1) : 0; - if(0xD800 <= x && x <= 0xDBFF && 0xDC00 <= y && y <= 0xDFFF) - { - x = 0x10000 + ((x & 0x03FF) << 10) + (y & 0x03FF); - i++; - } - - /* Encode output as utf-8 */ - if(x <= 0x7F) - output += String.fromCharCode(x); - else if(x <= 0x7FF) - output += String.fromCharCode(0xC0 | ((x >>> 6 ) & 0x1F), - 0x80 | ( x & 0x3F)); - else if(x <= 0xFFFF) - output += String.fromCharCode(0xE0 | ((x >>> 12) & 0x0F), - 0x80 | ((x >>> 6 ) & 0x3F), - 0x80 | ( x & 0x3F)); - else if(x <= 0x1FFFFF) - output += String.fromCharCode(0xF0 | ((x >>> 18) & 0x07), - 0x80 | ((x >>> 12) & 0x3F), - 0x80 | ((x >>> 6 ) & 0x3F), - 0x80 | ( x & 0x3F)); - } - return output; -} - -/* - * Encode a string as utf-16 - */ -function str2rstr_utf16le(input) -{ - var output = ""; - for(var i = 0; i < input.length; i++) - output += String.fromCharCode( input.charCodeAt(i) & 0xFF, - (input.charCodeAt(i) >>> 8) & 0xFF); - return output; -} - -function str2rstr_utf16be(input) -{ - var output = ""; - for(var i = 0; i < input.length; i++) - output += String.fromCharCode((input.charCodeAt(i) >>> 8) & 0xFF, - input.charCodeAt(i) & 0xFF); - return output; -} - -/* - * Convert a raw string to an array of little-endian words - * Characters >255 have their high-byte silently ignored. - */ -function rstr2binl(input) -{ - var output = Array(input.length >> 2); - for(var i = 0; i < output.length; i++) - output[i] = 0; - for(var i = 0; i < input.length * 8; i += 8) - output[i>>5] |= (input.charCodeAt(i / 8) & 0xFF) << (i%32); - return output; -} - -/* - * Convert an array of little-endian words to a string - */ -function binl2rstr(input) -{ - var output = ""; - for(var i = 0; i < input.length * 32; i += 8) - output += String.fromCharCode((input[i>>5] >>> (i % 32)) & 0xFF); - return output; -} - -/* - * Calculate the MD5 of an array of little-endian words, and a bit length. - */ -function binl_md5(x, len) -{ - /* append padding */ - x[len >> 5] |= 0x80 << ((len) % 32); - x[(((len + 64) >>> 9) << 4) + 14] = len; - - var a = 1732584193; - var b = -271733879; - var c = -1732584194; - var d = 271733878; - - for(var i = 0; i < x.length; i += 16) - { - var olda = a; - var oldb = b; - var oldc = c; - var oldd = d; - - a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); - d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); - c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); - b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); - a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); - d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426); - c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341); - b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983); - a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416); - d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417); - c = md5_ff(c, d, a, b, x[i+10], 17, -42063); - b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); - a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); - d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); - c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); - b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); - - a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); - d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); - c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); - b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); - a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); - d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083); - c = md5_gg(c, d, a, b, x[i+15], 14, -660478335); - b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848); - a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438); - d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690); - c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961); - b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); - a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); - d = md5_gg(d, a, b, c, x[i+