Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
5fac458f
Commit
5fac458f
authored
Aug 18, 2017
by
fabriziopandini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Main work -- refactor certs phase
parent
38053c3e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
0 deletions
+66
-0
certs.go
cmd/kubeadm/app/phases/certs/certs.go
+0
-0
certs_test.go
cmd/kubeadm/app/phases/certs/certs_test.go
+0
-0
util.go
cmd/kubeadm/test/certs/util.go
+55
-0
util.go
cmd/kubeadm/test/util.go
+11
-0
No files found.
cmd/kubeadm/app/phases/certs/certs.go
View file @
5fac458f
This diff is collapsed.
Click to expand it.
cmd/kubeadm/app/phases/certs/certs_test.go
View file @
5fac458f
This diff is collapsed.
Click to expand it.
cmd/kubeadm/test/certs/util.go
View file @
5fac458f
...
...
@@ -19,6 +19,7 @@ package certs
import
(
"crypto/rsa"
"crypto/x509"
"net"
"testing"
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/pkiutil"
...
...
@@ -35,6 +36,13 @@ func SetupCertificateAuthorithy(t *testing.T) (*x509.Certificate, *rsa.PrivateKe
return
caCert
,
caKey
}
// AssertCertificateIsCa is a utility function for kubeadm testing that asserts if a given certificate is a CA
func
AssertCertificateIsCa
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
)
{
if
!
cert
.
IsCA
{
t
.
Error
(
"cert is not a valida CA"
)
}
}
// AssertCertificateIsSignedByCa is a utility function for kubeadm testing that asserts if a given certificate is signed
// by the expected CA
func
AssertCertificateIsSignedByCa
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
,
signingCa
*
x509
.
Certificate
)
{
...
...
@@ -77,3 +85,50 @@ func AssertCertificateHasClientAuthUsage(t *testing.T, cert *x509.Certificate) {
}
t
.
Error
(
"cert has not ClientAuth usage as expected"
)
}
// AssertCertificateHasServerAuthUsage is a utility function for kubeadm testing that asserts if a given certificate has
// the expected ExtKeyUsageServerAuth
func
AssertCertificateHasServerAuthUsage
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
)
{
for
i
:=
range
cert
.
ExtKeyUsage
{
if
cert
.
ExtKeyUsage
[
i
]
==
x509
.
ExtKeyUsageServerAuth
{
return
}
}
t
.
Error
(
"cert is not a ServerAuth"
)
}
// AssertCertificateHasDNSNames is a utility function for kubeadm testing that asserts if a given certificate has
// the expected DNSNames
func
AssertCertificateHasDNSNames
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
,
DNSNames
...
string
)
{
for
_
,
DNSName
:=
range
DNSNames
{
found
:=
false
for
_
,
val
:=
range
cert
.
DNSNames
{
if
val
==
DNSName
{
found
=
true
break
}
}
if
!
found
{
t
.
Errorf
(
"cert does not contain DNSName %s"
,
DNSName
)
}
}
}
// AssertCertificateHasIPAddresses is a utility function for kubeadm testing that asserts if a given certificate has
// the expected IPAddresses
func
AssertCertificateHasIPAddresses
(
t
*
testing
.
T
,
cert
*
x509
.
Certificate
,
IPAddresses
...
net
.
IP
)
{
for
_
,
IPAddress
:=
range
IPAddresses
{
found
:=
false
for
_
,
val
:=
range
cert
.
IPAddresses
{
if
val
.
Equal
(
IPAddress
)
{
found
=
true
break
}
}
if
!
found
{
t
.
Errorf
(
"cert does not contain IPAddress %s"
,
IPAddress
)
}
}
}
cmd/kubeadm/test/util.go
View file @
5fac458f
...
...
@@ -76,6 +76,17 @@ func SetupMasterConfigurationFile(t *testing.T, tmpdir string, cfg *kubeadmapi.M
return
cfgPath
}
// SetupEmptyFiles is a utility function for kubeadm testing that creates one or more empty files (touch)
func
SetupEmptyFiles
(
t
*
testing
.
T
,
tmpdir
string
,
fileNames
...
string
)
{
for
_
,
fileName
:=
range
fileNames
{
newFile
,
err
:=
os
.
Create
(
filepath
.
Join
(
tmpdir
,
fileName
))
if
err
!=
nil
{
t
.
Fatalf
(
"Error creating file %s in %s: %v"
,
fileName
,
tmpdir
,
err
)
}
newFile
.
Close
()
}
}
// SetupPkiDirWithCertificateAuthorithy is a utility function for kubeadm testing that creates a
// CertificateAuthorithy cert/key pair into /pki subfolder of a given temporary directory.
// The funtion returns the path of the created pki.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment