Skip to content

Commit

Permalink
DEV: Fix lint and clean-up tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
udan11 committed May 25, 2019
1 parent 918658c commit 441d9bc
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 133 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import computed from "ember-addons/ember-computed-decorators";
import {
ENCRYPT_ACTIVE,
getEncryptionStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ function decryptElements(containerSelector, elementSelector) {
*/
export function decryptTitles() {
decryptElements("h1[data-topic-id]", ".fancy-title");
decryptElements(".topic-list-item[data-topic-id], .latest-topic-list-item[data-topic-id]", ".title");
decryptElements(
".topic-list-item[data-topic-id], .latest-topic-list-item[data-topic-id]",
".title"
);
decryptElements("a.topic-link[data-topic-id]", "span");
decryptElements("a.topic-link[data-topic-id]");
decryptElements("a.raw-topic-link[data-topic-id]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import {
ENCRYPT_ACTIVE,
getEncryptionStatus,
hasTopicKey,
hasTopicKey
} from "discourse/plugins/discourse-encrypt/lib/discourse";
import { getTopicKey } from "discourse/plugins/discourse-encrypt/lib/discourse";

Expand Down
10 changes: 4 additions & 6 deletions spec/models/post_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
revisor.revise!(user, raw: 'this post is unencrypted and has been edited')
end

it 'hides version for encrypted posts' do
expect(post.version).to eq(1)
expect(post.public_version).to eq(1)

expect(post2.version).to eq(2)
expect(post2.public_version).to eq(2)
context '#is_encrypted?' do
it 'works' do
expect(post.is_encrypted?).to eq(true)
end
end

end
120 changes: 0 additions & 120 deletions spec/requests/encrypt_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,126 +139,6 @@
end
end

context '#update_topic' do
it 'does not work when not logged in' do
put '/encrypt/topic', params: {
topic_id: topic.id,
title: '-- other encrypted title --',
keys: {
user.username => '-- other key of user --',
user2.username => '-- other key of user2 --'
}
}

expect(response.status).to eq(403)
expect(topic.custom_fields['encrypted_title']).to eq('-- the encrypted title --')
expect(store.get("key_#{topic.id}_#{user.id}")).to eq('-- the key of user --')
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- the key of user2 --')
end

it 'does not work for users who cannot see topic' do
sign_in(user3)

put '/encrypt/topic', params: {
topic_id: topic.id,
title: '-- other encrypted title --',
keys: {
user.username => '-- other key of user --',
user2.username => '-- other key of user2 --'
}
}

expect(response.status).to eq(403)
expect(topic.custom_fields['encrypted_title']).to eq('-- the encrypted title --')
expect(store.get("key_#{topic.id}_#{user.id}")).to eq('-- the key of user --')
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- the key of user2 --')
end

it 'saves encrypted topic data' do
sign_in(user)

put '/encrypt/topic', params: {
topic_id: other_topic.id,
title: '-- other encrypted title --',
keys: {
user.username => '-- other key of user --',
user2.username => '-- other key of user2 --'
}
}

expect(response.status).to eq(200)
expect(other_topic.custom_fields['encrypted_title']).to eq('-- other encrypted title --')
expect(store.get("key_#{other_topic.id}_#{user.id}")).to eq('-- other key of user --')
expect(store.get("key_#{other_topic.id}_#{user2.id}")).to eq('-- other key of user2 --')
end

it 'saves encrypted topic title' do
sign_in(user)

put '/encrypt/topic', params: {
topic_id: topic.id,
title: '-- new encrypted title --',
}

topic.reload

expect(response.status).to eq(200)
expect(topic.custom_fields['encrypted_title']).to eq('-- new encrypted title --')
expect(store.get("key_#{topic.id}_#{user.id}")).to eq('-- the key of user --')
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- the key of user2 --')
end

it 'saves encrypted topic key for each user' do
sign_in(user)

put '/encrypt/topic', params: {
topic_id: topic.id,
keys: {
user.username => '-- new key of user --',
user2.username => '-- new key of user2 --'
}
}

expect(response.status).to eq(200)
expect(topic.custom_fields['encrypted_title']).to eq('-- the encrypted title --')
expect(store.get("key_#{topic.id}_#{user.id}")).to eq('-- new key of user --')
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- new key of user2 --')
end
end

context '#destroy_topic' do
it 'does not work when not logged in' do
delete '/encrypt/topic', params: { topic_id: topic.id, usernames: [ user.username ] }

expect(response.status).to eq(403)
expect(store.get("key_#{topic.id}_#{user.id}")).to eq('-- the key of user --')
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- the key of user2 --')
end

it 'does not work for users who cannot see topic' do
sign_in(user3)

delete '/encrypt/topic', params: { topic_id: topic.id, usernames: [ user.username ] }

expect(response.status).to eq(403)
expect(store.get("key_#{topic.id}_#{user.id}")).to eq('-- the key of user --')
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- the key of user2 --')
end

it 'deletes topic keys' do
sign_in(user)

expect(store.get("key_#{topic.id}_#{user.id}")).to eq('-- the key of user --')
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- the key of user2 --')

delete '/encrypt/topic', params: { topic_id: topic.id, usernames: [ user.username ] }

expect(response.status).to eq(200)
expect(store.get("key_#{topic.id}_#{user.id}")).to eq(nil)
expect(store.get("key_#{topic.id}_#{user2.id}")).to eq('-- the key of user2 --')
end
end

context '#reset_user' do
before do
user.custom_fields['encrypt_public_key'] = '-- the public key --'
Expand Down
4 changes: 0 additions & 4 deletions test/javascripts/acceptance/encrypt-test.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@ test("posting does not leak plaintext", async assert => {
await setEncryptionStatus(ENCRYPT_ACTIVE);

globalAssert = assert;
/* global server */
server.put("/encrypt/topic", () => {
return [200, { "Content-Type": "application/json" }, { success: "OK" }];
});

const composerActions = selectKit(".composer-actions");

Expand Down

0 comments on commit 441d9bc

Please sign in to comment.