Skip to content

Commit cf1c995

Browse files
qmfrederikbrendandburns
authored andcommitted
Run integration tests as part of CI (after #129) (#131)
* Run CI scripts on both Mac and Linux * Fix AuthTests for macOS * Use SocketsHttpHandler * Install minikube on the Travis CI servers * Add integration tests * Fix an issue where StreamConnectAsync would crash if the credentials were not set
1 parent 12769b6 commit cf1c995

File tree

6 files changed

+126
-19
lines changed

6 files changed

+126
-19
lines changed

.travis.yml

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1+
sudo: required
2+
dist: trusty
3+
4+
os:
5+
- osx
6+
- linux
7+
18
language: csharp
2-
sudo: false
3-
matrix:
4-
include:
5-
- mono: none
6-
dist: trusty
7-
# We need the .NET Core 2.1 (preview 1) SDK to build. Travis doesn't know how to install this yet.
8-
before_install:
9-
- echo 'Installing .NET Core...'
10-
- export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
11-
- export DOTNET_CLI_TELEMETRY_OPTOUT=1
12-
- curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
13-
- sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
14-
- sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
15-
- sudo apt-get -qq update
16-
- sudo apt-get install -y dotnet-sdk-2.1.300-preview1-008174
9+
mono: none
10+
env:
11+
global:
12+
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
13+
- DOTNET_CLI_TELEMETRY_OPTOUT=1
14+
- COMPlus_UseManagedHttpClientHandler=true
15+
16+
# minikube-related changes
17+
- CHANGE_MINIKUBE_NONE_USER=true
18+
- MINIKUBE_WANTREPORTERRORPROMPT=false
19+
- MINIKUBE_WANTUPDATENOTIFICATION=false
20+
- KUBECONFIG=/home/travis/.kube/config
21+
22+
# We need the .NET Core 2.1 (preview 1) SDK to build. Travis doesn't know how to install this yet.
23+
before_install:
24+
- ./install-$TRAVIS_OS_NAME.sh
1725

1826
script:
1927
- ./ci.sh
28+
29+
after_script:
30+
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then ./integration-tests.sh; fi

examples/nginx.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: nginx
5+
spec:
6+
containers:
7+
- name: nginx
8+
image: nginx:1.7.9
9+
ports:
10+
- containerPort: 80

install-linux.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
echo 'Installing .NET Core...'
3+
4+
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
5+
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
6+
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
7+
sudo apt-get -qq update
8+
sudo apt-get install -y dotnet-sdk-2.1.300-preview1-008174
9+
10+
echo 'Installing kubecl'
11+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl
12+
chmod +x kubectl
13+
sudo mv kubectl /usr/local/bin/
14+
15+
echo 'Installing minikube'
16+
curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.25.0/minikube-linux-amd64
17+
chmod +x minikube
18+
sudo mv minikube /usr/local/bin/
19+
20+
echo 'Creating the minikube cluster'
21+
sudo minikube start --vm-driver=none --kubernetes-version=v1.9.0 --extra-config=apiserver.Authorization.Mode=RBAC
22+
minikube update-context
23+
minikube addons disable dashboard
24+
25+
echo 'Waiting for the cluster nodes to be ready'
26+
JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; \
27+
until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done

install-osx.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
echo 'Installing .NET Core...'
3+
4+
wget https://download.microsoft.com/download/D/7/8/D788D3CD-44C4-487D-829B-413E914FB1C3/dotnet-sdk-2.1.300-preview1-008174-osx-x64.pkg -O ~/dotnet-sdk-2.1.300-preview1-008174-osx-x64.pkg
5+
sudo installer -pkg ~/dotnet-sdk-2.1.300-preview1-008174-osx-x64.pkg -target /
6+
7+
# https://github.com/dotnet/cli/issues/2544
8+
ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/

integration-tests.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
cd examples
3+
4+
echo 'Creating a nginx pod in the default namespace'
5+
kubectl create -f nginx.yml
6+
7+
echo 'Running the simple example'
8+
cd simple
9+
dotnet run
10+
11+
echo 'Running the exec example'
12+
cd ../exec
13+
dotnet run
14+
15+
echo 'Running the labels example'
16+
cd ../labels
17+
dotnet run
18+
19+
echo 'Running the namespace example'
20+
cd ../namespace
21+
dotnet run

tests/AuthTests.cs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Net;
55
using System.Net.Http.Headers;
6+
using System.Security.Cryptography;
67
using System.Security.Cryptography.X509Certificates;
78
using System.Text;
89
using System.Threading.Tasks;
@@ -11,6 +12,9 @@
1112
using Microsoft.AspNetCore.Hosting;
1213
using Microsoft.AspNetCore.Server.Kestrel.Https;
1314
using Microsoft.Rest;
15+
using Org.BouncyCastle.Crypto.Parameters;
16+
using Org.BouncyCastle.Pkcs;
17+
using Org.BouncyCastle.Security;
1418
using Xunit;
1519
using Xunit.Abstractions;
1620

@@ -46,7 +50,7 @@ public void Anonymous()
4650

4751
using (var server = new MockKubeApiServer(TestOutput, cxt =>
4852
{
49-
cxt.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
53+
cxt.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
5054
return Task.FromResult(false);
5155
}))
5256
{
@@ -76,7 +80,7 @@ public void BasicAuth()
7680

7781
if (header != expect)
7882
{
79-
cxt.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
83+
cxt.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
8084
return Task.FromResult(false);
8185
}
8286

@@ -167,8 +171,13 @@ public void Cert()
167171

168172
var clientCertificateKeyData = File.ReadAllText("assets/client-key-data.txt");
169173
var clientCertificateData = File.ReadAllText("assets/client-certificate-data.txt");
174+
175+
X509Certificate2 serverCertificate = null;
176+
using (MemoryStream serverCertificateStream = new MemoryStream(Convert.FromBase64String(serverCertificateData)))
177+
{
178+
serverCertificate = OpenCertificateStore(serverCertificateStream);
179+
}
170180

171-
var serverCertificate = new X509Certificate2(Convert.FromBase64String(serverCertificateData), "");
172181
var clientCertificate = new X509Certificate2(Convert.FromBase64String(clientCertificateData), "");
173182

174183
var clientCertificateValidationCalled = false;
@@ -263,7 +272,7 @@ public void Token()
263272

264273
if (header != expect)
265274
{
266-
cxt.Response.StatusCode = (int) HttpStatusCode.Unauthorized;
275+
cxt.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
267276
return Task.FromResult(false);
268277
}
269278

@@ -319,6 +328,27 @@ public void Token()
319328
Assert.Equal(HttpStatusCode.Unauthorized, listTask.Response.StatusCode);
320329
}
321330
}
331+
}
332+
333+
private X509Certificate2 OpenCertificateStore(Stream stream)
334+
{
335+
Pkcs12Store store = new Pkcs12Store();
336+
store.Load(stream, new char[] { });
337+
338+
var keyAlias = store.Aliases.Cast<string>().SingleOrDefault(a => store.IsKeyEntry(a));
339+
340+
var key = (RsaPrivateCrtKeyParameters)store.GetKey(keyAlias).Key;
341+
var bouncyCertificate = store.GetCertificate(keyAlias).Certificate;
342+
343+
var certificate = new X509Certificate2(DotNetUtilities.ToX509Certificate(bouncyCertificate));
344+
var parameters = DotNetUtilities.ToRSAParameters(key);
345+
346+
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
347+
rsa.ImportParameters(parameters);
348+
349+
certificate = RSACertificateExtensions.CopyWithPrivateKey(certificate, rsa);
350+
351+
return certificate;
322352
}
323353
}
324354
}

0 commit comments

Comments
 (0)