Skip to content

Commit f7eae0b

Browse files
David Morcilloslickepinneleio10mrcasals
authored
Add the key ceremony (decidim#6967)
Co-authored-by: slickepinne <[email protected]> Co-authored-by: Leonardo Diez <[email protected]> Co-authored-by: Marc Riera <[email protected]>
1 parent 2f01b14 commit f7eae0b

File tree

57 files changed

+1226
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1226
-111
lines changed

Gemfile.lock

+33-11
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ PATH
141141
i18n-tasks (~> 0.9.18)
142142
mdl (~> 0.5)
143143
nokogiri (>= 1.10.8)
144+
puffing-billy (~> 2.4.0)
144145
puma (>= 4.3)
145146
rails-controller-testing (~> 1.0)
146147
rspec-cells (~> 0.3.4)
@@ -159,7 +160,7 @@ PATH
159160
webmock (~> 3.6)
160161
wisper-rspec (~> 1.0)
161162
decidim-elections (0.24.0.dev)
162-
decidim-bulletin_board (= 0.2.0)
163+
decidim-bulletin_board (= 0.6.1)
163164
decidim-core (= 0.24.0.dev)
164165
decidim-forms (= 0.24.0.dev)
165166
decidim-proposals (= 0.24.0.dev)
@@ -307,7 +308,7 @@ GEM
307308
browser (2.7.1)
308309
builder (3.2.4)
309310
byebug (11.1.3)
310-
capybara (3.33.0)
311+
capybara (3.34.0)
311312
addressable
312313
mini_mime (>= 0.1.3)
313314
nokogiri (~> 1.8)
@@ -331,7 +332,7 @@ GEM
331332
actionpack (>= 3.0)
332333
cells (>= 4.1.6, < 5.0.0)
333334
charlock_holmes (0.7.7)
334-
chef-utils (16.6.14)
335+
chef-utils (16.8.14)
335336
childprocess (3.0.0)
336337
coercible (1.0.0)
337338
descendants_tracker (~> 0.0.1)
@@ -344,6 +345,7 @@ GEM
344345
coffee-script-source (1.12.2)
345346
colorize (0.8.1)
346347
concurrent-ruby (1.1.7)
348+
cookiejar (0.3.3)
347349
crack (0.4.4)
348350
crass (1.0.6)
349351
css_parser (1.7.1)
@@ -354,12 +356,11 @@ GEM
354356
db-query-matchers (0.9.0)
355357
activesupport (>= 4.0, <= 6.0)
356358
rspec (~> 3.0)
357-
decidim-bulletin_board (0.2.0)
358-
activemodel (~> 5.0, >= 5.0.0.1)
359-
activesupport (~> 5.0, >= 5.0.0.1)
359+
decidim-bulletin_board (0.6.1)
360360
byebug (~> 11.0)
361361
graphlient (~> 0.4.0)
362-
jwt
362+
jwt (~> 2.2.2)
363+
rails (>= 5.0.0)
363364
wisper (~> 2.0.0)
364365
declarative-builder (0.1.0)
365366
declarative-option (< 0.2.0)
@@ -388,6 +389,16 @@ GEM
388389
doorkeeper (5.4.0)
389390
railties (>= 5)
390391
doorkeeper-i18n (4.0.1)
392+
em-http-request (1.1.7)
393+
addressable (>= 2.3.4)
394+
cookiejar (!= 0.3.1)
395+
em-socksify (>= 0.3)
396+
eventmachine (>= 1.0.3)
397+
http_parser.rb (>= 0.6.0)
398+
em-socksify (0.3.2)
399+
eventmachine (>= 1.0.0.beta.4)
400+
em-synchrony (1.0.6)
401+
eventmachine (>= 1.0.0.beta.1)
391402
equalizer (0.0.11)
392403
erb_lint (0.0.35)
393404
activesupport
@@ -402,6 +413,8 @@ GEM
402413
erubi (1.9.0)
403414
etherpad-lite (0.3.0)
404415
rest-client (>= 1.6)
416+
eventmachine (1.2.7)
417+
eventmachine_httpserver (0.2.1)
405418
execjs (2.7.0)
406419
factory_bot (4.11.1)
407420
activesupport (>= 3.0.0)
@@ -450,9 +463,10 @@ GEM
450463
http-accept (1.7.0)
451464
http-cookie (1.0.3)
452465
domain_name (~> 0.5)
466+
http_parser.rb (0.6.0)
453467
i18n (1.8.5)
454468
concurrent-ruby (~> 1.0)
455-
i18n-tasks (0.9.31)
469+
i18n-tasks (0.9.33)
456470
activesupport (>= 4.0.2)
457471
ast (>= 2.1.0)
458472
erubi
@@ -527,7 +541,7 @@ GEM
527541
mixlib-cli (2.1.8)
528542
mixlib-config (3.0.9)
529543
tomlrb
530-
mixlib-shellout (3.1.7)
544+
mixlib-shellout (3.2.2)
531545
chef-utils
532546
msgpack (1.3.3)
533547
multi_json (1.15.0)
@@ -589,6 +603,14 @@ GEM
589603
actionmailer (>= 3)
590604
premailer (~> 1.7, >= 1.7.9)
591605
public_suffix (4.0.6)
606+
puffing-billy (2.4.0)
607+
addressable (~> 2.5)
608+
em-http-request (~> 1.1, >= 1.1.0)
609+
em-synchrony
610+
eventmachine (~> 1.2)
611+
eventmachine_httpserver
612+
http_parser.rb (~> 0.6.0)
613+
multi_json
592614
puma (5.0.0)
593615
nio4r (~> 2.0)
594616
racc (1.5.2)
@@ -768,7 +790,7 @@ GEM
768790
thor (1.0.1)
769791
thread_safe (0.3.6)
770792
tilt (2.0.10)
771-
tomlrb (1.3.0)
793+
tomlrb (2.0.1)
772794
truncato (0.7.11)
773795
htmlentities (~> 4.3.1)
774796
nokogiri (>= 1.7.0, <= 2.0)
@@ -799,7 +821,7 @@ GEM
799821
activemodel (>= 5.0)
800822
bindex (>= 0.4.0)
801823
railties (>= 5.0)
802-
webmock (3.9.3)
824+
webmock (3.11.0)
803825
addressable (>= 2.3.6)
804826
crack (>= 0.3.2)
805827
hashdiff (>= 0.4.0, < 2.0.0)

config/i18n-tasks.yml

+1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ ignore_unused:
294294
- decidim.debates.debate_m.commented_time_ago
295295
- decidim.elections.trustee_zone.trustees.show.identification_keys.upload_error.*
296296
- decidim.elections.feedback.answer.*
297+
- decidim.elections.trustee_zone.elections.key_ceremony_steps.keys.*
297298
- decidim.votings.admin_log.*
298299

299300

decidim-dev/decidim-dev.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
3030
s.add_dependency "i18n-tasks", "~> 0.9.18"
3131
s.add_dependency "mdl", "~> 0.5"
3232
s.add_dependency "nokogiri", ">= 1.10.8"
33+
s.add_dependency "puffing-billy", "~> 2.4.0"
3334
s.add_dependency "puma", ">= 4.3"
3435
s.add_dependency "rails-controller-testing", "~> 1.0"
3536
s.add_dependency "rspec-cells", "~> 0.3.4"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"alg":"RS256","e":"AQAB","kty":"RSA","n":"mYW4py55eHVzlAOLeWSlkX-UzFcWmPZNgt38YgfDsrWsMiF99NxeS1hHBBBAIMYVj4DdraunxwxibFZJm4B7JfLedO02pGHXWpx-VUSwRU7TKBO8KGcLIuyIsLAn4VZmcUCfOD4z4D3mOPXJFrmy_db4EQJgQnkRQdop9Nb-zExjYdw9IOnSFYdYLJ6k-g4Onu43kUIVDjBBwBlNHIkr-zpApPWhABUpSV_Vy6WAdku3ix4MyFQLQ48ljJp4KVKrw85km3x5k1p7yXpRXaeAUwdl1ucZUHgeb23ED-q2gwASAbrBLOMlrrRrexObRXlHd7gkQS4fwvLtehENY0EepaS6R9ZDGD5l8AJOlS3jGCBfQdpL9aJT05ZqmB8Vi0Fj8PgDkzselqp9eSwUBb82bp8padX9NsZPaokXLtJls8acSOPpBDwmEPAiUML7LWUwiRylimK4CVDNxulNGnBuPlYl5b4vZQHtpjBEFfKUZxI8qY1Y2qpEehaYD0oXa64yr2Hi5IVdlCOS88hqPskPttoe28cm6YVYflJP9bv4slqeu1cafDSCxX7A4PX83wDpW5gyWC3cXAPTXh2Plxlnn3p9KTae6_YPkI8Id26zkm61LpKi-CkQCvo2fHvfZI23JiSj3Y9KYZR25Ym8O9aaNBdhgvNKhB8VFlizKet3VU8"}

decidim-dev/lib/decidim/dev/test/rspec_support/component_context.rb

+17-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
let(:user) { create :user, :confirmed, organization: organization }
77

8-
let!(:organization) { create(:organization, available_authorizations: %w(dummy_authorization_handler another_dummy_authorization_handler)) }
8+
let!(:organization) { create(:organization, *organization_traits, available_authorizations: %w(dummy_authorization_handler another_dummy_authorization_handler)) }
99

1010
let(:participatory_process) do
1111
create(:participatory_process, :with_steps, organization: organization)
@@ -22,8 +22,14 @@
2222
let!(:category) { create :category, participatory_space: participatory_space }
2323
let!(:scope) { create :scope, organization: organization }
2424

25+
let(:organization_traits) { [] }
26+
2527
before do
26-
switch_to_host(organization.host)
28+
if organization_traits.include?(:secure_context)
29+
switch_to_secure_context_host
30+
else
31+
switch_to_host(organization.host)
32+
end
2733
end
2834

2935
def visit_component
@@ -32,9 +38,12 @@ def visit_component
3238
end
3339

3440
shared_context "when managing a component" do
35-
include_context "with a component"
41+
include_context "with a component" do
42+
let(:organization_traits) { component_organization_traits }
43+
end
3644

3745
let(:current_component) { component }
46+
let(:component_organization_traits) { [] }
3847

3948
before do
4049
login_as user, scope: :user
@@ -56,7 +65,11 @@ def edit_component_path(component)
5665
end
5766

5867
shared_context "when managing a component as an admin" do
59-
include_context "when managing a component"
68+
include_context "when managing a component" do
69+
let(:component_organization_traits) { admin_component_organization_traits }
70+
end
71+
72+
let(:admin_component_organization_traits) { [] }
6073

6174
let(:user) do
6275
create :user,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
require "billy/capybara/rspec"
4+
5+
Billy.configure do |config|
6+
config.cache = true
7+
config.persist_cache = true
8+
config.cache_path = "spec/billy"
9+
config.record_requests = true
10+
config.proxied_request_connect_timeout = 20
11+
config.proxied_request_inactivity_timeout = 20
12+
end
13+
14+
RSpec.configure do |config|
15+
config.before :each, :billy do
16+
driven_by :selenium_chrome_headless_billy
17+
switch_to_secure_context_host
18+
WebMock::HttpLibAdapters::EmHttpRequestAdapter.disable!
19+
end
20+
end

decidim-dev/lib/decidim/dev/test/rspec_support/vcr.rb

+17-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
require "vcr"
44

5+
module BulletinBoardVcr
6+
def self.bulletin_board_uri?(uri)
7+
uri.hostname == bulletin_board_uri.hostname && uri.port == bulletin_board_uri.port
8+
end
9+
10+
def self.bulletin_board_uri
11+
@bulletin_board_uri ||= URI(bulletin_board_server)
12+
end
13+
14+
def self.bulletin_board_server
15+
return "" unless defined?(Decidim::Elections)
16+
17+
Decidim::Elections.bulletin_board.server
18+
end
19+
end
20+
521
VCR.configure do |config|
622
config.default_cassette_options = { serialize_with: :json }
723
config.cassette_library_dir = "spec/cassettes"
824
config.hook_into :webmock
925
config.configure_rspec_metadata!
10-
config.ignore_request do |request|
11-
if defined?(Decidim::Elections)
12-
URI(request.uri).port != URI(Decidim::Elections.bulletin_board.server).port
13-
else
14-
true
15-
end
16-
end
26+
config.ignore_request { |request| !BulletinBoardVcr.bulletin_board_uri?(URI(request.uri)) }
1727
end

decidim-dev/lib/decidim/dev/test/rspec_support/download_helper.rb decidim-dev/lib/decidim/dev/test/rspec_support/z_download_helper.rb

+12-14
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ module DownloadHelper
44
TIMEOUT = 10
55
PATH = Rails.root.join("tmp/downloads").freeze
66

7-
def downloads
8-
Dir[PATH.join("*")]
7+
def downloads(name = nil)
8+
Dir[PATH.join(name || "*")]
99
end
1010

11-
def download_path
12-
wait_for_download
13-
downloads.first
11+
def download_path(name = nil)
12+
wait_for_download(name)
13+
downloads(name).first
1414
end
1515

16-
def download_content
17-
wait_for_download
18-
File.read(download_path)
16+
def download_content(name = nil)
17+
wait_for_download(name)
18+
File.read(download_path(name))
1919
end
2020

21-
def wait_for_download
21+
def wait_for_download(name = nil)
2222
Timeout.timeout(TIMEOUT) do
23-
sleep 0.1 until downloaded?
23+
sleep 0.1 until downloaded?(name)
2424
end
2525
end
2626

27-
def downloaded?
28-
downloads.any? && !downloading?
27+
def downloaded?(name = nil)
28+
downloads(name).any? && !downloading?
2929
end
3030

3131
def downloading?
@@ -40,8 +40,6 @@ def clear_downloads
4040
RSpec.configure do |config|
4141
config.include DownloadHelper, download: true
4242
config.before :each, download: true do
43-
driven_by(:headless_chrome)
44-
switch_to_default_host
4543
FileUtils.mkdir_p DownloadHelper::PATH.to_s
4644
page.driver.browser.download_path = DownloadHelper::PATH.to_s
4745
clear_downloads

decidim-elections/app/assets/javascripts/decidim/elections/identification_keys.js.es6

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
((exports) => {
66
class IdentificationKeys {
7-
constructor(trusteeId, storedPublicKey) {
7+
constructor(trusteeUniqueId, storedPublicKey) {
88
this.format = "jwk";
99
this.algorithm = {
1010
name: "RSASSA-PKCS1-v1_5",
@@ -16,11 +16,11 @@
1616
this.publicKeyAttrs = ["alg", "e", "kty", "n"];
1717
this.jwtHeader = this._encode64(JSON.stringify({alg: "RS256", typ: "JWT"}));
1818

19-
this.trusteeId = trusteeId;
19+
this.trusteeUniqueId = trusteeUniqueId;
2020
this.privateKey = null;
2121
this.publicKey = null;
2222
this.storedPublicKey = JSON.parse(storedPublicKey || null);
23-
this.keyIdentifier = `${trusteeId}_identification_key`;
23+
this.keyIdentifier = `${trusteeUniqueId}-private-key`;
2424
this.browserSupport = this._checkBrowserSupport();
2525
this.textEncoder = new TextEncoder("utf-8");
2626

@@ -113,15 +113,14 @@
113113
return this._clear();
114114
}
115115

116-
sign(payload) {
116+
async sign(payload) {
117117
if (!this.browserSupport || this.privateKey === null) {
118118
return false;
119119
}
120120

121121
const data = `${this.jwtHeader}.${this._encode64(JSON.stringify(payload))}`;
122-
const signature = this.crypto.subtle.sign(this.algorithm.name, this.privateKey, this.textEncoder.encode(data));
123-
124-
return `${data}.${this._encode64(signature)}`;
122+
const signature = await this.crypto.subtle.sign(this.algorithm, this.privateKey, this.textEncoder.encode(data));
123+
return `${data}.${btoa(Reflect.apply(String.fromCharCode, null, new Uint8Array(signature))).replace(/[=]/g, "").replace(/\+/g, "-").replace(/\//g, "_")}`;
125124
}
126125

127126
_checkBrowserSupport() {

decidim-elections/app/assets/javascripts/decidim/elections/trustee_zone.js.es6

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ window.Decidim = window.Decidim || {};
77
$(() => {
88
function identificationKeys() {
99
const $form = $(".trustee_zone form");
10-
const $trusteeId = $("#trustee_id", $form);
10+
const $trusteeUniqueId = $("#trustee_unique_id", $form);
1111
const $trusteePublicKey = $("#trustee_public_key", $form);
1212

13-
window.trusteeIdentificationKeys = new window.Decidim.IdentificationKeys(`trustee-${$trusteeId.val()}`, $trusteePublicKey.val());
13+
window.trusteeIdentificationKeys = new window.Decidim.IdentificationKeys($trusteeUniqueId.val(), $trusteePublicKey.val());
1414
if (!window.trusteeIdentificationKeys.browserSupport) {
1515
$("#not_supported_browser").addClass("visible");
1616
return;

0 commit comments

Comments
 (0)