@@ -28,6 +28,7 @@ import (
28
28
"net/url"
29
29
"os"
30
30
"os/exec"
31
+ "path"
31
32
"path/filepath"
32
33
"regexp"
33
34
"runtime"
@@ -57,10 +58,17 @@ func TestFunctional(t *testing.T) {
57
58
profile := UniqueProfileName ("functional" )
58
59
ctx , cancel := context .WithTimeout (context .Background (), Minutes (40 ))
59
60
defer func () {
61
+ if ! * cleanup {
62
+ return
63
+ }
60
64
p := localSyncTestPath ()
61
65
if err := os .Remove (p ); err != nil {
62
66
t .Logf ("unable to remove %s: %v" , p , err )
63
67
}
68
+ p = localTestCertPath ()
69
+ if err := os .Remove (p ); err != nil {
70
+ t .Logf ("unable to remove %s: %v" , p , err )
71
+ }
64
72
CleanupWithLogs (t , profile , cancel )
65
73
}()
66
74
@@ -110,6 +118,7 @@ func TestFunctional(t *testing.T) {
110
118
{"SSHCmd" , validateSSHCmd },
111
119
{"MySQL" , validateMySQL },
112
120
{"FileSync" , validateFileSync },
121
+ {"CertSync" , validateCertSync },
113
122
{"UpdateContextCmd" , validateUpdateContextCmd },
114
123
{"DockerEnv" , validateDockerEnv },
115
124
{"NodeLabels" , validateNodeLabels },
@@ -731,6 +740,16 @@ func localSyncTestPath() string {
731
740
return filepath .Join (localpath .MiniPath (), "/files" , vmSyncTestPath ())
732
741
}
733
742
743
+ // testCert is name of the test certificate installed
744
+ func testCert () string {
745
+ return fmt .Sprintf ("%d.pem" , os .Getpid ())
746
+ }
747
+
748
+ // localTestCertPath is where the test file will be synced into the VM
749
+ func localTestCertPath () string {
750
+ return filepath .Join (localpath .MiniPath (), "/certs" , testCert ())
751
+ }
752
+
734
753
// Copy extra file into minikube home folder for file sync test
735
754
func setupFileSync (ctx context.Context , t * testing.T , profile string ) {
736
755
p := localSyncTestPath ()
@@ -739,6 +758,11 @@ func setupFileSync(ctx context.Context, t *testing.T, profile string) {
739
758
if err != nil {
740
759
t .Fatalf ("copy: %v" , err )
741
760
}
761
+
762
+ err = copy .Copy ("./testdata/minikube_test.pem" , localTestCertPath ())
763
+ if err != nil {
764
+ t .Fatalf ("copy: %v" , err )
765
+ }
742
766
}
743
767
744
768
// validateFileSync to check existence of the test file
@@ -766,6 +790,39 @@ func validateFileSync(ctx context.Context, t *testing.T, profile string) {
766
790
}
767
791
}
768
792
793
+ // validateCertSync to check existence of the test certificate
794
+ func validateCertSync (ctx context.Context , t * testing.T , profile string ) {
795
+ if NoneDriver () {
796
+ t .Skipf ("skipping: ssh unsupported by none" )
797
+ }
798
+
799
+ want , err := ioutil .ReadFile ("./testdata/minikube_test.pem" )
800
+ if err != nil {
801
+ t .Errorf ("test file not found: %v" , err )
802
+ }
803
+
804
+ // Check both the installed & reference certs (they should be symlinked)
805
+ paths := []string {
806
+ path .Join ("/etc/ssl/certs" , testCert ()),
807
+ path .Join ("/usr/share/ca-certificates" , testCert ()),
808
+ // hashed path generated by: 'openssl x509 -hash -noout -in testCert()'
809
+ "/etc/ssl/certs/51391683.0" ,
810
+ }
811
+ for _ , vp := range paths {
812
+ t .Logf ("Checking for existence of %s within VM" , vp )
813
+ rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "ssh" , fmt .Sprintf ("cat %s" , vp )))
814
+ if err != nil {
815
+ t .Errorf ("%s failed: %v" , rr .Args , err )
816
+ }
817
+
818
+ // Strip carriage returned by ssh
819
+ got := strings .Replace (rr .Stdout .String (), "\r " , "" , - 1 )
820
+ if diff := cmp .Diff (string (want ), got ); diff != "" {
821
+ t .Errorf ("minikube_test.pem -> %s mismatch (-want +got):\n %s" , vp , diff )
822
+ }
823
+ }
824
+ }
825
+
769
826
// validateUpdateContextCmd asserts basic "update-context" command functionality
770
827
func validateUpdateContextCmd (ctx context.Context , t * testing.T , profile string ) {
771
828
rr , err := Run (t , exec .CommandContext (ctx , Target (), "-p" , profile , "update-context" , "--alsologtostderr" , "-v=2" ))
0 commit comments