Exemple #1
0
    def test_scenario_1_simple_vote(self):
        with ConsoleLogDuration("### administrator_creates_election"):
            self.administrator_creates_election()

        with ConsoleLogDuration(
                "### administrator_regenerates_passwords_for_some_voters"):
            self.administrator_regenerates_passwords_for_some_voters()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#0)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration("### all_voters_vote_in_sequences"):
            self.all_voters_vote_in_sequences()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#1)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration("### create_election_data_snapshot (#0)"):
            snapshot_folder = create_election_data_snapshot(self.election_id)
            console_log("snapshot_folder: ", snapshot_folder)

        try:
            with ConsoleLogDuration("### some_voters_revote"):
                self.some_voters_revote()

            with ConsoleLogDuration(
                    "### verify_election_consistency using `belenios_tool verify-diff` (#2)"
            ):
                verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            with ConsoleLogDuration("### delete_election_data_snapshot"):
                delete_election_data_snapshot(snapshot_folder)

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#3)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration("### administrator_does_tallying_of_election"):
            self.administrator_does_tallying_of_election()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#4)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration(
                "### one_voter_revotes_after_the_election_is_closed"):
            self.one_voter_revotes_after_the_election_is_closed()
Exemple #2
0
    def test_scenario_1_simple_vote(self):
        console_log("### Starting step: administrator_creates_election")
        self.administrator_creates_election(nh_question=True)
        console_log("### Step complete: administrator_creates_election")

        console_log("### Starting step: administrator_regenerates_passwords_for_some_voters")
        self.administrator_regenerates_passwords_for_some_voters()
        console_log("### Step complete: administrator_regenerates_passwords_for_some_voters")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (0)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (0)")

        console_log("### Starting step: all_voters_vote_in_sequences")
        self.all_voters_vote_in_sequences()
        console_log("### Step complete: all_voters_vote_in_sequences")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (1)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (1)")

        console_log("### Starting step: create_election_data_snapshot (0)")
        snapshot_folder = create_election_data_snapshot(self.election_id)
        console_log("### Step complete: create_election_data_snapshot (0)")

        try:
            console_log("### Starting step: some_voters_revote")
            self.some_voters_revote()
            console_log("### Step complete: some_voters_revote")

            console_log("### Starting step: verify_election_consistency using `belenios_tool verify-diff` (0)")
            verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            delete_election_data_snapshot(snapshot_folder)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify-diff` (0)")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (2)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (2)")

        console_log("### Starting step: administrator_does_tallying_of_election")
        self.administrator_does_tallying_of_election()
        console_log("### Step complete: administrator_does_tallying_of_election")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (3)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (3)")

        console_log("### Starting step: voter votes after the election is closed")
        self.one_voter_revotes_after_the_election_is_closed()
        console_log("### Step complete: voter votes after the election is closed")
Exemple #3
0
    def test_scenario_1_simple_vote(self):
        console_log("### Starting step: administrator_creates_election")
        self.administrator_creates_election()
        console_log("### Step complete: administrator_creates_election")

        console_log("### Starting step: administrator_regenerates_passwords_for_some_voters")
        self.administrator_regenerates_passwords_for_some_voters()
        console_log("### Step complete: administrator_regenerates_passwords_for_some_voters")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (0)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (0)")

        console_log("### Starting step: all_voters_vote_in_sequences")
        self.all_voters_vote_in_sequences()
        console_log("### Step complete: all_voters_vote_in_sequences")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (1)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (1)")

        console_log("### Starting step: create_election_data_snapshot (0)")
        snapshot_folder = create_election_data_snapshot(self.election_id)
        console_log("### Step complete: create_election_data_snapshot (0)")

        try:
            console_log("### Starting step: some_voters_revote")
            self.some_voters_revote()
            console_log("### Step complete: some_voters_revote")

            console_log("### Starting step: verify_election_consistency using `belenios_tool verify-diff` (0)")
            verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            delete_election_data_snapshot(snapshot_folder)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify-diff` (0)")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (2)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (2)")

        console_log("### Starting step: administrator_does_tallying_of_election")
        self.administrator_does_tallying_of_election()
        console_log("### Step complete: administrator_does_tallying_of_election")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (3)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (3)")

        console_log("### Starting step: voter votes after the election is closed")
        self.one_voter_revotes_after_the_election_is_closed()
        console_log("### Step complete: voter votes after the election is closed")
    def some_voters_vote_in_sequences(self, voters=None, start_index=0, end_index=None, verify_every_x_votes=5):
        """
        Iterates over `voters` from index `start_index` to `end_index`, cast their vote, and checks vote data consistency for every batch of `verify_every_x_votes` votes (using `belenios_tool verify-diff` and a snapshot of election data copied in previous batch).
        """
        if start_index < 0:
            raise Exception("start_index cannot be below 0")
        current_start_index = start_index
        if end_index is None:
            end_index = settings.NUMBER_OF_VOTING_VOTERS
        elif end_index > settings.NUMBER_OF_VOTING_VOTERS:
            raise Exception("end_index cannot exceeed NUMBER_OF_VOTING_VOTERS")

        if voters is None:
            voters = self.voters_email_addresses
        voters_who_will_vote_now = voters[start_index:end_index]
        voters_who_will_vote_now_data = populate_credential_and_password_for_voters_from_sent_emails(self.fake_sent_emails_manager, voters_who_will_vote_now, settings.ELECTION_TITLE)
        voters_who_will_vote_now_data = populate_random_votes_for_voters(voters_who_will_vote_now_data)
        self.update_voters_data(voters_who_will_vote_now_data)
        snapshot_folder = None

        while current_start_index < end_index:
            increment = verify_every_x_votes # could be randomized
            current_end_index = current_start_index + increment
            if current_end_index > end_index:
                current_end_index = end_index

            if current_start_index > 0:
                console_log("#### Starting substep: create_election_data_snapshot")
                snapshot_folder = create_election_data_snapshot(self.election_id)
                console_log("#### Substep complete: create_election_data_snapshot")

            try:
                console_log("#### A batch of " + str(current_end_index - current_start_index) + " voters, indexed " + str(current_start_index) + " to " + str(current_end_index - 1) + " are now going to vote")
                self.some_voters_cast_their_vote(voters_who_will_vote_now_data[current_start_index:current_end_index])
                console_log("#### A batch of " + str(current_end_index - current_start_index) + " voters, indexed " + str(current_start_index) + " to " + str(current_end_index - 1) + " have now voted")

                if current_start_index > 0:
                    console_log("#### Starting substep: verify_election_consistency using `belenios_tool verify-diff` (for a batch of votes)")
                    verify_election_consistency(self.election_id, snapshot_folder)
                    console_log("#### Substep complete: verify_election_consistency using `belenios_tool verify-diff` (for a batch of votes)")
            finally:
                if current_start_index > 0:
                    console_log("#### Starting substep: delete_election_data_snapshot")
                    delete_election_data_snapshot(snapshot_folder)
                    console_log("#### Substep complete: delete_election_data_snapshot")

            current_start_index += increment
Exemple #5
0
    def test_scenario_2_manual_vote(self):
        console_log(
            "### Running test method BeleniosTestElectionScenario2::test_scenario_2_manual_vote()"
        )
        with ConsoleLogDuration(
                "### administrator_starts_creation_of_manual_election"):
            self.administrator_starts_creation_of_manual_election()

        with ConsoleLogDuration(
                "### credential_authority_sends_credentials_to_voters"):
            self.credential_authority_sends_credentials_to_voters()

        with ConsoleLogDuration("### administrator_invites_trustees"):
            self.administrator_invites_trustees()

        with ConsoleLogDuration("### trustees_generate_election_private_keys"):
            self.trustees_generate_election_private_keys()

        with ConsoleLogDuration(
                "### administrator_completes_creation_of_election"):
            self.administrator_completes_creation_of_election()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#0)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration("### all_voters_vote_in_sequences"):
            self.all_voters_vote_in_sequences()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#1)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration(
                "### Starting step: create_election_data_snapshot (#0)"):
            snapshot_folder = create_election_data_snapshot(self.election_id)
            console_log("snapshot_folder: ", snapshot_folder)

        try:
            with ConsoleLogDuration("### some_voters_revote"):
                self.some_voters_revote()

            with ConsoleLogDuration(
                    "### verify_election_consistency using `belenios_tool verify-diff` (#2)"
            ):
                verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            with ConsoleLogDuration("### delete_election_data_snapshot"):
                delete_election_data_snapshot(snapshot_folder)

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#3)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration(
                "### administrator_starts_tallying_of_election"):
            self.administrator_starts_tallying_of_election()

        with ConsoleLogDuration("### trustees_do_partial_decryption"):
            self.trustees_do_partial_decryption()

        with ConsoleLogDuration(
                "### administrator_finishes_tallying_of_election"):
            self.administrator_finishes_tallying_of_election()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#4)"
        ):
            verify_election_consistency(self.election_id)
Exemple #6
0
    def test_scenario_2_manual_vote(self):
        console_log("### Starting step: administrator_starts_creation_of_manual_election")
        self.administrator_starts_creation_of_manual_election()
        console_log("### Step complete: administrator_starts_creation_of_manual_election")

        console_log("### Starting step: credential_authority_sends_credentials_to_voters")
        self.credential_authority_sends_credentials_to_voters()
        console_log("### Step complete: credential_authority_sends_credentials_to_voters")

        console_log("### Starting step: administrator_invites_trustees")
        self.administrator_invites_trustees()
        console_log("### Step complete: administrator_invites_trustees")

        console_log("### Starting step: trustees_generate_election_private_keys")
        self.trustees_generate_election_private_keys()
        console_log("### Step complete: trustees_generate_election_private_keys")

        console_log("### Starting step: administrator_completes_creation_of_election")
        self.administrator_completes_creation_of_election()
        console_log("### Step complete: administrator_completes_creation_of_election")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (0)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (0)")

        console_log("### Starting step: all_voters_vote_in_sequences")
        self.all_voters_vote_in_sequences()
        console_log("### Step complete: all_voters_vote_in_sequences")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (1)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (1)")

        console_log("### Starting step: create_election_data_snapshot (0)")
        snapshot_folder = create_election_data_snapshot(self.election_id)
        console_log("### Step complete: create_election_data_snapshot (0)")

        try:
            console_log("### Starting step: some_voters_revote")
            self.some_voters_revote()
            console_log("### Step complete: some_voters_revote")

            console_log("### Starting step: verify_election_consistency using `belenios_tool verify-diff` (0)")
            verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            delete_election_data_snapshot(snapshot_folder)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify-diff` (0)")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (2)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (2)")

        console_log("### Starting step: administrator_starts_tallying_of_election")
        self.administrator_starts_tallying_of_election()
        console_log("### Step complete: administrator_starts_tallying_of_election")

        console_log("### Starting step: trustees_do_partial_decryption")
        self.trustees_do_partial_decryption()
        console_log("### Step complete: trustees_do_partial_decryption")

        console_log("### Starting step: administrator_finishes_tallying_of_election")
        self.administrator_finishes_tallying_of_election()
        console_log("### Step complete: administrator_finishes_tallying_of_election")

        console_log("### Starting step: verify_election_consistency using `belenios_tool verify` (3)")
        verify_election_consistency(self.election_id)
        console_log("### Step complete: verify_election_consistency using `belenios_tool verify` (3)")
    def some_voters_vote_in_sequences(self,
                                      voters=None,
                                      start_index=0,
                                      end_index=None,
                                      verify_every_x_votes=5):
        """
        Iterates over `voters` from index `start_index` (included) to `end_index` (not included), cast their vote, and checks vote data consistency for every batch of `verify_every_x_votes` votes (using `belenios_tool verify-diff` and a snapshot of election data copied in previous batch).
        """
        if start_index < 0:
            raise Exception("start_index cannot be below 0")
        current_start_index = start_index
        if end_index is None:
            end_index = settings.NUMBER_OF_VOTING_VOTERS
        elif end_index > settings.NUMBER_OF_VOTING_VOTERS:
            raise Exception("end_index cannot exceeed NUMBER_OF_VOTING_VOTERS")

        if voters is None:
            voters = self.voters_email_addresses
        voters_who_will_vote_now = voters[start_index:end_index]
        voters_who_will_vote_now_data = populate_credential_and_password_for_voters_from_sent_emails(
            self.fake_sent_emails_manager, voters_who_will_vote_now,
            settings.ELECTION_TITLE)
        voters_who_will_vote_now_data = populate_random_votes_for_voters(
            voters_who_will_vote_now_data)
        self.update_voters_data(voters_who_will_vote_now_data)
        snapshot_folder = None

        while current_start_index < end_index:
            increment = verify_every_x_votes  # could be randomized
            current_end_index = current_start_index + increment
            if current_end_index > end_index:
                current_end_index = end_index

            if current_start_index > 0:
                console_log(
                    "#### Starting substep: create_election_data_snapshot")
                snapshot_folder = create_election_data_snapshot(
                    self.election_id)
                console_log(
                    "#### Substep complete: create_election_data_snapshot")

            try:
                console_log("#### A batch of " +
                            str(current_end_index - current_start_index) +
                            " voters, indexed " + str(current_start_index) +
                            " to " + str(current_end_index - 1) +
                            " included are now going to vote")
                sublist_start_index = current_start_index - start_index
                sublist_end_index = current_end_index - start_index
                self.some_voters_cast_their_vote(voters_who_will_vote_now_data[
                    sublist_start_index:sublist_end_index])
                console_log("#### A batch of " +
                            str(current_end_index - current_start_index) +
                            " voters, indexed " + str(current_start_index) +
                            " to " + str(current_end_index - 1) +
                            " included have now voted")

                if current_start_index > 0:
                    console_log(
                        "#### Starting substep: verify_election_consistency using `belenios_tool verify-diff` (for a batch of votes)"
                    )
                    verify_election_consistency(self.election_id,
                                                snapshot_folder)
                    console_log(
                        "#### Substep complete: verify_election_consistency using `belenios_tool verify-diff` (for a batch of votes)"
                    )
            finally:
                if current_start_index > 0:
                    console_log(
                        "#### Starting substep: delete_election_data_snapshot")
                    delete_election_data_snapshot(snapshot_folder)
                    console_log(
                        "#### Substep complete: delete_election_data_snapshot")

            current_start_index += increment
    def test_scenario_4_manual_vote_with_threshold(self):
        console_log(
            "### Running test method BeleniosTestElectionScenario4::test_scenario_4_manual_vote_with_threshold()"
        )
        console_log(
            "### Starting step: administrator_starts_creation_of_manual_election"
        )
        self.administrator_starts_creation_of_manual_election()
        console_log(
            "### Step complete: administrator_starts_creation_of_manual_election"
        )

        console_log(
            "### Starting step: credential_authority_sends_credentials_to_voters"
        )
        self.credential_authority_sends_credentials_to_voters()
        console_log(
            "### Step complete: credential_authority_sends_credentials_to_voters"
        )

        console_log(
            "### Starting step: administrator_invites_trustees_and_sets_threshold"
        )
        self.administrator_invites_trustees_and_sets_threshold()
        console_log(
            "### Step complete: administrator_invites_trustees_and_sets_threshold"
        )

        console_log(
            "### Starting step: trustees_do_initialization_step_1_of_3")
        self.trustees_do_initialization_step_1_of_3()
        console_log(
            "### Step complete: trustees_do_initialization_step_1_of_3")

        console_log(
            "### Starting step: trustees_do_initialization_step_2_of_3")
        self.trustees_do_initialization_step_2_of_3()
        console_log(
            "### Step complete: trustees_do_initialization_step_2_of_3")

        console_log(
            "### Starting step: trustees_do_initialization_step_3_of_3")
        self.trustees_do_initialization_step_3_of_3()
        console_log(
            "### Step complete: trustees_do_initialization_step_3_of_3")

        console_log(
            "### Starting step: administrator_completes_creation_of_election")
        self.administrator_completes_creation_of_election()
        console_log(
            "### Step complete: administrator_completes_creation_of_election")

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (0)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (0)"
        )

        console_log("### Starting step: all_voters_vote_in_sequences")
        self.all_voters_vote_in_sequences()
        console_log("### Step complete: all_voters_vote_in_sequences")

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (1)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (1)"
        )

        console_log("### Starting step: create_election_data_snapshot (0)")
        snapshot_folder = create_election_data_snapshot(self.election_id)
        console_log("### Step complete: create_election_data_snapshot (0)")

        try:
            console_log("### Starting step: some_voters_revote")
            self.some_voters_revote()
            console_log("### Step complete: some_voters_revote")

            console_log(
                "### Starting step: verify_election_consistency using `belenios_tool verify-diff` (0)"
            )
            verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            delete_election_data_snapshot(snapshot_folder)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify-diff` (0)"
        )

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (2)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (2)"
        )

        console_log(
            "### Starting step: administrator_starts_tallying_of_election")
        self.administrator_starts_tallying_of_election(
            settings.TRUSTEES_THRESHOLD_VALUE)
        console_log(
            "### Step complete: administrator_starts_tallying_of_election")

        console_log("### Starting step: trustees_do_partial_decryption")
        self.trustees_do_partial_decryption(settings.TRUSTEES_THRESHOLD_VALUE)
        console_log("### Step complete: trustees_do_partial_decryption")

        console_log(
            "### Starting step: administrator_finishes_tallying_of_election")
        self.administrator_finishes_tallying_of_election(
            settings.TRUSTEES_THRESHOLD_VALUE)
        console_log(
            "### Step complete: administrator_finishes_tallying_of_election")

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (3)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (3)"
        )
Exemple #9
0
    def test_scenario_2_manual_vote(self):
        console_log(
            "### Starting step: administrator_starts_creation_of_manual_election"
        )
        self.administrator_starts_creation_of_manual_election()
        console_log(
            "### Step complete: administrator_starts_creation_of_manual_election"
        )

        console_log(
            "### Starting step: credential_authority_sends_credentials_to_voters"
        )
        self.credential_authority_sends_credentials_to_voters()
        console_log(
            "### Step complete: credential_authority_sends_credentials_to_voters"
        )

        console_log("### Starting step: administrator_invites_trustees")
        self.administrator_invites_trustees()
        console_log("### Step complete: administrator_invites_trustees")

        console_log(
            "### Starting step: trustees_generate_election_private_keys")
        self.trustees_generate_election_private_keys()
        console_log(
            "### Step complete: trustees_generate_election_private_keys")

        console_log(
            "### Starting step: administrator_completes_creation_of_election")
        self.administrator_completes_creation_of_election()
        console_log(
            "### Step complete: administrator_completes_creation_of_election")

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (0)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (0)"
        )

        console_log("### Starting step: all_voters_vote_in_sequences")
        self.all_voters_vote_in_sequences()
        console_log("### Step complete: all_voters_vote_in_sequences")

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (1)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (1)"
        )

        console_log("### Starting step: create_election_data_snapshot (0)")
        snapshot_folder = create_election_data_snapshot(self.election_id)
        console_log("### Step complete: create_election_data_snapshot (0)")

        try:
            console_log("### Starting step: some_voters_revote")
            self.some_voters_revote()
            console_log("### Step complete: some_voters_revote")

            console_log(
                "### Starting step: verify_election_consistency using `belenios_tool verify-diff` (0)"
            )
            verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            delete_election_data_snapshot(snapshot_folder)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify-diff` (0)"
        )

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (2)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (2)"
        )

        console_log(
            "### Starting step: administrator_starts_tallying_of_election")
        self.administrator_starts_tallying_of_election()
        console_log(
            "### Step complete: administrator_starts_tallying_of_election")

        console_log("### Starting step: trustees_do_partial_decryption")
        self.trustees_do_partial_decryption()
        console_log("### Step complete: trustees_do_partial_decryption")

        console_log(
            "### Starting step: administrator_finishes_tallying_of_election")
        self.administrator_finishes_tallying_of_election()
        console_log(
            "### Step complete: administrator_finishes_tallying_of_election")

        console_log(
            "### Starting step: verify_election_consistency using `belenios_tool verify` (3)"
        )
        verify_election_consistency(self.election_id)
        console_log(
            "### Step complete: verify_election_consistency using `belenios_tool verify` (3)"
        )
Exemple #10
0
    def test_load_testing_set_up(self):
        # Create (if it does not exist) folder that will contain all files created by this script
        os.makedirs(settings.GENERATED_FILES_DESTINATION_FOLDER, exist_ok=True)

        # Download server's sent emails text file, so that we know up to which line number we have to ignore its contents (this is its last line)
        temporary_fake_sent_emails_manager = None
        try:
            temporary_fake_sent_emails_manager = self.download_all_sent_emails(
            )
            self.fake_sent_emails_initial_lines_count = temporary_fake_sent_emails_manager.count_lines(
            )
            console_log(
                "### Initial lines count of server's fake sent emails file:",
                self.fake_sent_emails_initial_lines_count)
        finally:
            if temporary_fake_sent_emails_manager:
                temporary_fake_sent_emails_manager.uninstall_fake_sendmail_log_file(
                )

        console_log(
            "### Running test method BeleniosLoadTestingSetUp::test_load_testing_set_up()"
        )
        console_log(
            "### Starting step: administrator_starts_creation_of_manual_election"
        )
        self.administrator_starts_creation_of_manual_election()
        console_log(
            "### Step complete: administrator_starts_creation_of_manual_election"
        )

        self.election_id = admin_election_draft_page_url_to_election_id(
            self.draft_election_administration_page_url)

        console_log(
            "### Starting step: credential_authority_sends_locally_generated_credentials_to_server"
        )
        self.credential_authority_sends_locally_generated_credentials_to_server(
        )
        console_log(
            "### Step complete: credential_authority_sends_locally_generated_credentials_to_server"
        )

        console_log("### Starting step: administrator_invites_trustees")
        self.administrator_invites_trustees()
        console_log("### Step complete: administrator_invites_trustees")

        console_log(
            "### Starting step: trustees_generate_election_private_keys")
        self.trustees_generate_election_private_keys()
        console_log(
            "### Step complete: trustees_generate_election_private_keys")

        console_log(
            "### Starting step: administrator_completes_creation_of_election")
        self.administrator_completes_creation_of_election()
        console_log(
            "### Step complete: administrator_completes_creation_of_election")

        if settings.SERVER_URL == "http://localhost:8001":
            console_log(
                "### Starting step: verify_election_consistency using `belenios_tool verify`"
            )
            verify_election_consistency(self.election_id)
            console_log(
                "### Step complete: verify_election_consistency using `belenios_tool verify`"
            )

        console_log("### Starting step: download_all_sent_emails")
        self.distant_fake_sent_emails_manager = self.download_all_sent_emails()
        console_log("### Step complete: download_all_sent_emails")

        # Concatenate (distant) Belenios server's sent emails file (starting after line `fake_sent_emails_initial_lines_count`) and local credential authority's sent emails file into file `self.distant_fake_sent_emails_manager.log_file_path`, so that `self.generate_vote_ballots()` can parse it and find all information it needs.
        import subprocess
        import tempfile
        (file_handle, log_file_path) = tempfile.mkstemp(text=True)
        with open(log_file_path, 'w') as f:
            subprocess.run([
                "tail", "-n",
                "+" + str(self.fake_sent_emails_initial_lines_count + 1),
                self.distant_fake_sent_emails_manager.log_file_path
            ],
                           stdout=f)
            subprocess.run(
                ["cat", self.fake_sent_emails_manager.log_file_path], stdout=f)
        subprocess.run([
            "cp", log_file_path,
            self.distant_fake_sent_emails_manager.log_file_path
        ])
        subprocess.run(["rm", "-f", log_file_path])

        # Generate ballot for each voter
        console_log("### Starting step: generate_vote_ballots")
        self.generate_vote_ballots()
        console_log("### Step complete: generate_vote_ballots")

        # Export a CSV file to be imported by the jmeter load testing script. It contains fields 'voter_email_address', 'voter_password', 'voter_credential', 'voter_encrypted_ballot_file_name', 'election_page_url'
        console_log("### Starting step: export_all_votes_csv")
        self.export_all_votes_csv()
        console_log("### Step complete: export_all_votes_csv")
Exemple #11
0
    def test_scenario_2_manual_vote_with_monkeys(self):
        console_log(
            "### Running test method BeleniosTestElectionScenario2WithMonkeys::test_scenario_2_manual_vote_with_monkeys()"
        )
        with ConsoleLogDuration(
                "### administrator_starts_creation_of_manual_election"):
            self.administrator_starts_creation_of_manual_election()

        with ConsoleLogDuration(
                "### credential_authority_sends_credentials_to_voters"):
            self.credential_authority_sends_credentials_to_voters()

        with ConsoleLogDuration("### administrator_invites_trustees"):
            self.administrator_invites_trustees()

        with ConsoleLogDuration("### trustees_generate_election_private_keys"):
            self.trustees_generate_election_private_keys()

        with ConsoleLogDuration(
                "### administrator_completes_creation_of_election"):
            self.administrator_completes_creation_of_election()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#0)"
        ):
            verify_election_consistency(self.election_id)

        self.voters_data = {
        }  # We reset this (set by `BeleniosTestElectionWithCreationBase`) because we generate voters data in several parts
        voters_who_will_vote = random.sample(self.voters_email_addresses,
                                             settings.NUMBER_OF_VOTING_VOTERS)
        console_log("voters who will vote:", voters_who_will_vote)
        start_index_of_voters_who_vote_in_first_part = 0
        end_index_of_voters_who_vote_in_first_part = settings.NUMBER_OF_VOTING_VOTERS_IN_FIRST_PART
        console_log(
            f"number of (normal) voters who will vote in first part: {end_index_of_voters_who_vote_in_first_part} (indexes {start_index_of_voters_who_vote_in_first_part} included to {end_index_of_voters_who_vote_in_first_part} excluded)"
        )
        start_index_of_voters_who_vote_in_second_part = end_index_of_voters_who_vote_in_first_part
        end_index_of_voters_who_vote_in_second_part = end_index_of_voters_who_vote_in_first_part + settings.NUMBER_OF_MONKEY_VOTING_VOTERS
        console_log(
            f"number of (smart monkey) voters who will vote in second part: {end_index_of_voters_who_vote_in_second_part - start_index_of_voters_who_vote_in_second_part} (indexes {start_index_of_voters_who_vote_in_second_part} included to {end_index_of_voters_who_vote_in_second_part} excluded)"
        )
        start_index_of_voters_who_vote_in_third_part = end_index_of_voters_who_vote_in_second_part
        end_index_of_voters_who_vote_in_third_part = settings.NUMBER_OF_VOTING_VOTERS
        console_log(
            f"number of (normal) voters who will vote in third part: {end_index_of_voters_who_vote_in_third_part - start_index_of_voters_who_vote_in_third_part} (indexes {start_index_of_voters_who_vote_in_third_part} included to {end_index_of_voters_who_vote_in_third_part} excluded)"
        )
        verify_every_x_votes = 5

        with ConsoleLogDuration(
                "### some_voters_vote_in_sequences (first part)"):
            self.some_voters_vote_in_sequences(
                voters_who_will_vote,
                start_index=start_index_of_voters_who_vote_in_first_part,
                end_index=end_index_of_voters_who_vote_in_first_part,
                verify_every_x_votes=verify_every_x_votes)

        with ConsoleLogDuration("### smart monkeys vote (second part)"):
            smart_monkey_voters_who_will_vote_now = voters_who_will_vote[
                start_index_of_voters_who_vote_in_second_part:
                end_index_of_voters_who_vote_in_second_part]
            timeout = settings.EXPLICIT_WAIT_TIMEOUT
            voters_who_will_vote_now_data = populate_credential_and_password_for_voters_from_sent_emails(
                self.fake_sent_emails_manager,
                smart_monkey_voters_who_will_vote_now, settings.ELECTION_TITLE)
            voters_who_will_vote_now_data = populate_random_votes_for_voters(
                voters_who_will_vote_now_data)
            self.update_voters_data(voters_who_will_vote_now_data)

            for idx, voter in enumerate(voters_who_will_vote_now_data):
                console_log(
                    f"#### Voting as smart monkey {idx+1} of {settings.NUMBER_OF_MONKEY_VOTING_VOTERS}"
                )
                voter_email_address = voter["email_address"]
                voter_username = voter["username"]
                voter_password = voter["password"]
                voter_credential = voter["credential"]
                voter_decided_vote = voter["votes"]
                election_url = voter[
                    "election_page_url"]  # this is the same as `election_id_to_election_home_page_url(self.election_id)`
                smart_ballot_tracker = smart_monkey_votes(
                    self.browser, timeout, election_url, voter_username,
                    voter_password, voter_credential, voter_decided_vote)
                if smart_ballot_tracker:
                    voter["smart_ballot_tracker"] = smart_ballot_tracker
                else:
                    raise Exception(
                        "Monkey voter did not complete its vote properly")
                self.voters_email_addresses_who_have_voted[
                    voter_email_address] = True
                self.browser.quit()
                self.browser = initialize_browser_for_scenario_2()

        with ConsoleLogDuration(
                "### some_voters_vote_in_sequences (third part)"):
            self.some_voters_vote_in_sequences(
                voters_who_will_vote,
                start_index=start_index_of_voters_who_vote_in_third_part,
                end_index=end_index_of_voters_who_vote_in_third_part,
                verify_every_x_votes=verify_every_x_votes)

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#1)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration(
                "### Starting step: create_election_data_snapshot (#0)"):
            snapshot_folder = create_election_data_snapshot(self.election_id)
            console_log("snapshot_folder: ", snapshot_folder)

        try:
            with ConsoleLogDuration("### some_voters_revote"):
                self.some_voters_revote()

            with ConsoleLogDuration(
                    "### verify_election_consistency using `belenios_tool verify-diff` (#2)"
            ):
                verify_election_consistency(self.election_id, snapshot_folder)
        finally:
            with ConsoleLogDuration("### delete_election_data_snapshot"):
                delete_election_data_snapshot(snapshot_folder)

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#3)"
        ):
            verify_election_consistency(self.election_id)

        with ConsoleLogDuration(
                "### administrator_starts_tallying_of_election"):
            self.administrator_starts_tallying_of_election()

        with ConsoleLogDuration("### trustees_do_partial_decryption"):
            self.trustees_do_partial_decryption()

        with ConsoleLogDuration(
                "### administrator_finishes_tallying_of_election"):
            self.administrator_finishes_tallying_of_election()

        with ConsoleLogDuration(
                "### verify_election_consistency using `belenios_tool verify` (#4)"
        ):
            verify_election_consistency(self.election_id)