* 🔧 Scripts to manage electionguard

- Script to get electionguard release
- Script to migrate electionguard local build
- Update projects

*  Reduce Test

Tests were flooding due to repeated nunit test in KeyCeremony. Simplified to the simple election which is the only constant test. Temporarily ignored tests hingeing on release of file methods.

* 🚀 Update Pull Request Workflow

Simplify and remove blocks on tests

* Update Product to match Project

* 🔧 Package Workflow

Workflow to commit nuget package
This commit is contained in:
Keith Fung 2019-11-12 11:56:02 -05:00 коммит произвёл Ethan Chumley
Родитель 54dcfbbd03
Коммит 665cc3ad38
14 изменённых файлов: 212 добавлений и 242 удалений

24
.github/workflows/package-workflow.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,24 @@
name: Package
on:
milestone:
types: [closed]
jobs:
linux_package:
name: 'Linux'
runs-on: 'ubuntu-latest'
steps:
- uses: actions/checkout@master
with:
submodules: true
- name: Setup Commands
run: chmod +x ./scripts/download-latest.sh
- name: Configure Package Registry
run: sed -i 's/GITHUB_TOKEN/${{ secrets.GITHUB_TOKEN }}/g' nuget.config
- name: Build
run: dotnet build -c Release
- name: Package
run: dotnet pack -c Release
- name: Push
run: dotnet nuget push src/ElectionGuard/bin/Release/*.nupkg --source "github"

58
.github/workflows/pr-workflow.yml поставляемый
Просмотреть файл

@ -10,26 +10,17 @@ jobs:
- uses: actions/checkout@master
with:
submodules: true
- name: Upgrade cmake
run: |
sudo mv /usr/local/bin/cmake /usr/local/bin/cmake-old
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8611B7A28669BB93
sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ xenial main'
sudo apt-get update && sudo apt-get install -y cmake
cmake --version
- name: Build C Library
working-directory: ./libs/ElectionGuard-SDK-C-Implementation
run: |
cmake --version
cmake -S . -B build -DBUILD_SHARED_LIBS=ON
cmake --build build
- name: Setup Commands
run: chmod +x ./scripts/download-latest.sh
- name: Configure Nuget
run: sed -i 's/GITHUB_TOKEN/${{ secrets.GITHUB_TOKEN }}/g' nuget.config
- name: Build
run: dotnet build
run: dotnet build -c Release
- name: Test
if: false
run: dotnet test
if: false # Disabled
run: dotnet test -c Release
- name: Package
run: dotnet pack
run: dotnet pack -c Release
windows_build:
name: 'Windows Build'
runs-on: 'windows-latest'
@ -47,19 +38,14 @@ jobs:
run: |
pacman --noconfirm -Syu
pacman --noconfirm -S mingw-w64-x86_64-gcc mingw-w64-x86_64-gmp make
- name: Build C Library
working-directory: ./libs/ElectionGuard-SDK-C-Implementation
run: |
cmake --version
cmake -S . -B build -G "MSYS Makefiles" -DBUILD_SHARED_LIBS=ON
cmake --build build
- name: Configure Nuget
run: ((Get-Content -path nuget.config -Raw) -replace 'GITHUB_TOKEN','${{ secrets.GITHUB_TOKEN }}') | Set-Content -Path nuget.config
- name: Build
run: dotnet build
run: dotnet build -c Release
- name: Test
if: false
run: dotnet test
run: dotnet test -c Release
- name: Package
run: dotnet pack
run: dotnet pack -c Release
macos_build:
name: 'MacOS Build'
runs-on: 'macOS-latest'
@ -71,16 +57,14 @@ jobs:
run: brew install gmp
- name: Upgrade dotnet core sdk
run: brew cask install dotnet-sdk
- name: Build C Library
working-directory: ./libs/ElectionGuard-SDK-C-Implementation
run: |
cmake --version
cmake -S . -B build -DBUILD_SHARED_LIBS=ON
cmake --build build
- name: Setup Commands
run: chmod +x ./scripts/download-latest.sh
- name: Configure Nuget
run: sed -i '' 's/GITHUB_TOKEN/${{ secrets.GITHUB_TOKEN }}/' nuget.config
- name: Build
run: dotnet build
run: dotnet build -c Release
- name: Test
if: false
run: dotnet test
if: false # Disabled
run: dotnet test -c Release
- name: Package
run: dotnet pack
run: dotnet pack -c Release

3
.gitignore поставляемый
Просмотреть файл

@ -328,3 +328,6 @@ ASALocalRun/
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Built Libraries
[Ll]ibs/

13
nuget.config Normal file
Просмотреть файл

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="github" value="https://nuget.pkg.github.com/microsoft/index.json" />
</packageSources>
<packageSourceCredentials>
<github>
<add key="Username" value="microsoft" />
<add key="ClearTextPassword" value="GITHUB_TOKEN" />
</github>
</packageSourceCredentials>
</configuration>

Просмотреть файл

@ -0,0 +1,40 @@
# Download latest release from github
$repo = "microsoft/ElectionGuard-SDK-C-Implementation"
$file = "electionguard.zip"
$releases = "https://api.github.com/repos/$repo/releases"
Write-Host Determining latest release
$tag = (Invoke-WebRequest $releases | ConvertFrom-Json)[0].tag_name
$download = "https://github.com/$repo/releases/download/$tag/$file"
$name = $file.Split(".")[0]
$zip = "$name-$tag.zip"
$dir = "$name-$tag"
$dll = "$name.dll"
$so = "lib$name.so"
$dylib = "lib$name.dylib"
$lib_path = "..\..\libs\electionguard"
Write-Host Downloading latest release
Write-Host $download
Invoke-WebRequest $download -Out $zip
Write-Host Extracting release files
Expand-Archive $zip -Force
Write-Host Remove outdated library files
Remove-Item $lib_path -Recurse -Force -ErrorAction SilentlyContinue
Write-Host Validating library directory
New-Item -ItemType Directory -Force -Path $lib_path
Write-Host Move release files to library
Move-Item $dir\$dll\$dll -Destination $lib_path\$dll -Force
Move-Item $dir\$so\$so -Destination $lib_path\$so -Force
Move-Item $dir\$dylib\$dylib -Destination $lib_path\$dylib -Force
Write-Host Deleting temp files
Remove-Item $zip -Force
Remove-Item $dir -Recurse -Force

Просмотреть файл

@ -0,0 +1,40 @@
#!/bin/bash
REPO="microsoft/ElectionGuard-SDK-C-Implementation"
FILE="electionguard.zip"
RELEASES="https://api.github.com/repos/$REPO/releases"
echo "Determining latest release"
TAG="v1.0.0"
DOWNLOAD="https://github.com/$REPO/releases/download/$TAG/$FILE"
NAME="electionguard"
ZIP="$NAME-$TAG.zip"
DIR="$NAME-$TAG"
DLL="$NAME.dll"
SO="lib$NAME.so"
DYLIB="lib$NAME.dylib"
LIB_PATH="../../libs/electionguard"
echo "Downloading latest release"
curl -L $DOWNLOAD -o $ZIP
echo "Extracting release files"
sudo apt-get install unzip
unzip -o $ZIP -d $DIR
echo "Remove outdated library files"
rm -rf -v $LIB_PATH
echo "Validating library directory"
mkdir -p $LIB_PATH
echo "Move release files to library"
mv -f $DIR/$DLL/$DLL "$LIB_PATH/$DLL"
mv -f $DIR/$SO/$SO $LIB_PATH/$SO
mv -f $DIR/$DYLIB/$DYLIB $LIB_PATH/$DYLIB
echo "Deleting temp files"
rm -rf -v $ZIP
rm -rf -v $DIR

13
scripts/migrate-local.ps1 Normal file
Просмотреть файл

@ -0,0 +1,13 @@
$source="../../libs/ElectionGuard-SDK-C-Implementation/build" #location of starting directory
$destination="../../libs/electionguard"; #location where files will be copied to
$files=@("*electionguard*")
Write-Host Remove outdated library files
Remove-Item $destination -Recurse -Force -ErrorAction SilentlyContinue
Write-Host Validating library source and destination
New-Item -ItemType Directory -Force -Path $source
New-Item -ItemType Directory -Force -Path $destination
Write-Host Move build files to library
New-Item -ItemType Directory -Force -Path ($destination); Get-ChildItem -recurse ($source) -include ($files) | Copy-Item -Destination ($destination)

15
scripts/migrate-local.sh Normal file
Просмотреть файл

@ -0,0 +1,15 @@
#!/bin/bash
SOURCE="../../libs/ElectionGuard-SDK-C-Implementation/build" #location of starting directory
DESTINATION="../../libs/electionguard/"; #location where files will be copied to
FILES="*electionguard*"
echo "Remove outdated library files"
rm -rf -v $DESTINATION
echo "Validating library directory"
mkdir -p $DESTINATION
echo "Move build files to library"
find $SOURCE -type f -name $FILES -exec cp '{}' $DESTINATION ';'

Просмотреть файл

@ -2,10 +2,10 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<Company>Microsoft Corporation</Company>
<Product>ElectionGuard</Product>
<Product>ElectionGuard.SDK</Product>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Description>An open source software development kit (SDK) that makes voting more secure, transparent, accessible.</Description>
<Authors>ElectionGuard Team</Authors>
<Authors>Microsoft</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Microsoft Corporation</Copyright>
<PackageLicenseExpression></PackageLicenseExpression>
@ -13,21 +13,28 @@
<PackageProjectUrl>https://github.com/microsoft/ElectionGuard-SDK</PackageProjectUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>
<ItemGroup>
<LinuxLibrary Include="..\..\libs\ElectionGuard-SDK-C-Implementation\build\*.so" />
<MacOSLibrary Include="..\..\libs\ElectionGuard-SDK-C-Implementation\build\*.dylib" />
<WindowsLibrary Include="..\..\libs\ElectionGuard-SDK-C-Implementation\build\*.dll" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\LICENSE">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
<Target Name="CopyLibraries" AfterTargets="AfterBuild">
<Copy SourceFiles="@(LinuxLibrary)" DestinationFolder="$(OutDir)" />
<Copy SourceFiles="@(MacOSLibrary)" DestinationFolder="$(OutDir)" />
<Copy SourceFiles="@(WindowsLibrary)" DestinationFolder="$(OutDir)" />
</Target>
<Target Name="Windows_Debug" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Debug' And '$(OS)' == 'Windows_NT' ">
<Exec Command="powershell -Command &quot;&amp; { . \&quot;$(ProjectDir)..\..\scripts\migrate-local.ps1\&quot;; }&quot;"/>
</Target>
<Target Name="Windows_Release" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Release' And '$(OS)' == 'Windows_NT' ">
<Exec Command="powershell -Command &quot;&amp; { . \&quot;$(ProjectDir)..\..\scripts\download-latest.ps1\&quot;; }&quot;"/>
</Target>
<Target Name="Unix_Debug" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Debug' And '$(OS)' != 'Windows_NT' ">
<Exec Command="$(ProjectDir)..\..\scripts\migrate-local.sh"/>
</Target>
<Target Name="Unix_Release" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Release' And '$(OS)' != 'Windows_NT' ">
<Exec Command="$(ProjectDir)..\..\scripts\download-latest.sh"/>
</Target>
<Target Name="Copy" AfterTargets="AfterBuild">
<ItemGroup>
<ElectionGuard Pack="true" Include="..\..\libs\electionguard\*" />
</ItemGroup>
<Copy SourceFiles="@(ElectionGuard)" DestinationFolder="$(OutDir)" />
</Target>
</Project>

Просмотреть файл

@ -1,15 +0,0 @@
using NUnit.Framework;
namespace UnitTests.Decryption
{
[TestFixture]
public class DecryptionTests
{
[Test]
[Ignore("Requires a reusable voting results file")]
public void Test()
{
}
}
}

Просмотреть файл

@ -1,151 +0,0 @@
using System.Collections.Generic;
using ElectionGuard.SDK.Config;
using ElectionGuard.SDK.Cryptography;
using ElectionGuard.SDK.KeyCeremony;
using ElectionGuard.SDK.KeyCeremony.Coordinator;
using ElectionGuard.SDK.KeyCeremony.Messages;
using ElectionGuard.SDK.KeyCeremony.Trustee;
using ElectionGuard.SDK.StateManagement;
using NUnit.Framework;
namespace UnitTests.KeyCeremony
{
[TestFixture(1u, 1u)]
[TestFixture(2u, 2u)]
[TestFixture(3u, 3u)]
[TestFixture(4u, 4u)]
[TestFixture(5u, 5u)]
[TestFixture(6u, 6u)]
public class KeyCeremonyTests
{
private readonly byte[] _baseHashCode = { 0,0xff,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
private readonly uint _numberOfTrustees;
private readonly uint _threshold;
private CryptographyParameters _parameters;
private KeyCeremonyCoordinator _coordinator;
private List<KeyCeremonyTrustee> _trustees;
private AllKeysReceivedMessage _allKeysReceivedMessage;
private AllSharesReceivedMessage _allSharesReceivedMessage;
private List<TrusteeState> _trusteeStates;
public KeyCeremonyTests(uint numberOfTrustees = 1, uint threshold = 1)
{
_numberOfTrustees = numberOfTrustees;
_threshold = threshold;
}
[OneTimeSetUp]
public void OneTimeSetUp()
{
if (_numberOfTrustees > MaxValues.MaxTrustees || _threshold > MaxValues.MaxTrustees)
{
Assert.Ignore("Max Trustees Exceeded. Tests Ignored");
}
_parameters = new CryptographyParameters();
}
[Test, Order(1)]
public void InitializeKeyCeremonyTest()
{
_coordinator = new KeyCeremonyCoordinator(_numberOfTrustees, _threshold);
_trustees = new List<KeyCeremonyTrustee>();
_trusteeStates = new List<TrusteeState>();
for (uint i = 0; i < _numberOfTrustees; i++)
{
_trustees.Add(new KeyCeremonyTrustee(_numberOfTrustees, _threshold, i));
}
Assert.NotNull(_coordinator);
Assert.AreEqual(_numberOfTrustees, _trustees.Count);
}
[Test, Order(2)]
public void GenerateKeyTest()
{
var missingTrusteesKeysReturn = _coordinator.AllKeysReceived();
Assert.AreEqual(CoordinatorStatus.MissingTrustees, missingTrusteesKeysReturn.Status);
foreach (var trustee in _trustees)
{
var keyGeneratedReturn = trustee.GenerateKey(_baseHashCode);
Assert.AreEqual(TrusteeStatus.Success, keyGeneratedReturn.Status);
var keyReceivedStatus = _coordinator.ReceiveKey(keyGeneratedReturn.Message);
Assert.AreEqual(CoordinatorStatus.Success, keyReceivedStatus);
}
var allKeysReceivedReturn = _coordinator.AllKeysReceived();
Assert.AreEqual(CoordinatorStatus.Success, allKeysReceivedReturn.Status);
_allKeysReceivedMessage = allKeysReceivedReturn.Message;
}
[Test, Order(3)]
public void GenerateSharesTest()
{
var missingTrusteesSharesReturn = _coordinator.AllSharesReceived();
Assert.AreEqual(CoordinatorStatus.MissingTrustees, missingTrusteesSharesReturn.Status);
foreach (var trustee in _trustees)
{
var generateShareResponse = trustee.GenerateShares(_allKeysReceivedMessage);
Assert.AreEqual(TrusteeStatus.Success, generateShareResponse.Status);
var receiveShareStatus = _coordinator.ReceiveShares(generateShareResponse.Message);
Assert.AreEqual(CoordinatorStatus.Success, receiveShareStatus);
}
var allSharesReceivedReturn = _coordinator.AllSharesReceived();
Assert.AreEqual(CoordinatorStatus.Success, allSharesReceivedReturn.Status);
_allSharesReceivedMessage = allSharesReceivedReturn.Message;
}
[Test, Order(4)]
public void VerifySharesTest()
{
var missingTrusteesVerifiedSharesReturn = _coordinator.PublishJointKey();
Assert.AreEqual(CoordinatorStatus.MissingTrustees, missingTrusteesVerifiedSharesReturn.Status);
foreach (var trustee in _trustees)
{
var verifySharesReturn = trustee.VerifyShares(_allSharesReceivedMessage);
Assert.AreEqual(TrusteeStatus.Success, verifySharesReturn.Status);
var receivedVerifiedSharesStatus = _coordinator.ReceiveSharesVerification(verifySharesReturn.Message);
Assert.AreEqual(CoordinatorStatus.Success, receivedVerifiedSharesStatus);
}
var publishJointKeyReturn = _coordinator.PublishJointKey();
Assert.AreEqual(CoordinatorStatus.Success, publishJointKeyReturn.Status);
}
[Test, Order(5)]
public void ExportStateTest()
{
foreach (var trustee in _trustees)
{
var exportStateReturn = trustee.ExportState();
Assert.AreEqual(TrusteeStatus.Success, exportStateReturn.Status);
_trusteeStates.Add(exportStateReturn.State);
}
Assert.AreEqual(_numberOfTrustees, _trusteeStates.Count);
}
[Test, Order(6)]
public void KeyCeremonyDisposeTest()
{
_coordinator.Dispose();
foreach (var trustee in _trustees)
{
trustee.Dispose();
}
}
[OneTimeTearDown]
public void OneTimeTearDown()
{
_parameters.Dispose();
}
}
}

Просмотреть файл

@ -240,6 +240,7 @@ namespace UnitTests
}
[Test, Order(8), NonParallelizable]
[Ignore("Ignore until file format confirmed")]
[Category(VotingStage)]
public void Step08_ExportBallots()
{
@ -263,6 +264,7 @@ namespace UnitTests
}
[Test, Order(10), NonParallelizable]
[Ignore("Ignore until file format confirmed")]
[Category(DecryptionStage)]
public void Step10_TallyVotingRecords()
{
@ -276,6 +278,7 @@ namespace UnitTests
}
[Test, Order(11), NonParallelizable]
[Ignore("Ignore until file format confirmed")]
[Category(DecryptionStage)]
public void Step11_DecryptTallyShares()
{
@ -300,6 +303,7 @@ namespace UnitTests
}
[Test, Order(12), NonParallelizable]
[Ignore("Ignore until file format confirmed")]
[Category(DecryptionStage)]
public void Step12_DecryptTallyDecryptionFragments()
{

Просмотреть файл

@ -2,9 +2,9 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsPackable>false</IsPackable>
<Authors>ElectionGuard Team</Authors>
<Authors>Microsoft</Authors>
<Company>Microsoft Corporation</Company>
<Product>ElectionGuard</Product>
<Product>ElectionGuard.SDK</Product>
<Description>Unit tests for the ElectionGuard C# SDK Wrapper</Description>
<Copyright>Microsoft Corporation</Copyright>
</PropertyGroup>
@ -17,14 +17,22 @@
<ItemGroup>
<ProjectReference Include="..\..\src\ElectionGuard\ElectionGuard.SDK.csproj" />
</ItemGroup>
<ItemGroup>
<LinuxLibrary Include="..\..\libs\ElectionGuard-SDK-C-Implementation\build\*.so" />
<MacOSLibrary Include="..\..\libs\ElectionGuard-SDK-C-Implementation\build\*.dylib" />
<WindowsLibrary Include="..\..\libs\ElectionGuard-SDK-C-Implementation\build\*.dll" />
</ItemGroup>
<Target Name="CopyLibraries" AfterTargets="AfterBuild">
<Copy SourceFiles="@(LinuxLibrary)" DestinationFolder="$(OutDir)" />
<Copy SourceFiles="@(MacOSLibrary)" DestinationFolder="$(OutDir)" />
<Copy SourceFiles="@(WindowsLibrary)" DestinationFolder="$(OutDir)" />
<Target Name="Windows_Debug" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Debug' And '$(OS)' == 'Windows_NT' ">
<Exec Command="powershell -Command &quot;&amp; { . \&quot;$(ProjectDir)..\..\scripts\migrate-local.ps1\&quot;; }&quot;"/>
</Target>
<Target Name="Windows_Release" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Release' And '$(OS)' == 'Windows_NT' ">
<Exec Command="powershell -Command &quot;&amp; { . \&quot;$(ProjectDir)..\..\scripts\download-latest.ps1\&quot;; }&quot;"/>
</Target>
<Target Name="Unix_Debug" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Debug' And '$(OS)' != 'Windows_NT' ">
<Exec Command="$(ProjectDir)..\..\scripts\migrate-local.sh"/>
</Target>
<Target Name="Unix_Release" AfterTargets="BeforeBuild" Condition=" '$(Configuration)'=='Release' And '$(OS)' != 'Windows_NT' ">
<Exec Command="$(ProjectDir)..\..\scripts\download-latest.sh"/>
</Target>
<Target Name="Copy" AfterTargets="AfterBuild">
<ItemGroup>
<ElectionGuard Include="..\..\libs\electionguard\*" />
</ItemGroup>
<Copy SourceFiles="@(ElectionGuard)" DestinationFolder="$(OutDir)" />
</Target>
</Project>

Просмотреть файл

@ -1,15 +0,0 @@
using NUnit.Framework;
namespace UnitTests.Voting
{
[TestFixture]
public class VotingTests
{
[Test]
[Ignore("Require Joint Key to be isolated to test separately")]
public void Test()
{
}
}
}