forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitauth.go
95 lines (79 loc) · 3.86 KB
/
gitauth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package builds
import (
"fmt"
"net"
"net/url"
"path/filepath"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"
testutil "github.com/openshift/origin/test/util"
)
// hostname returns the hostname from a hostport specification
func hostname(hostport string) (string, error) {
host, _, err := net.SplitHostPort(hostport)
return host, err
}
var _ = g.Describe("builds: parallel: gitauth: Check build for private source repository access", func() {
defer g.GinkgoRecover()
const (
gitServerDeploymentConfigName = "gitserver"
sourceSecretName = "sourcesecret"
hostNameSuffix = "xip.io"
gitUserName = "gituser"
gitPassword = "gituserpassword"
buildConfigName = "gitauthtest"
sourceURLTemplate = "https://gitserver.%s/ruby-hello-world"
)
var (
gitServerFixture = exutil.FixturePath("fixtures", "test-gitserver.yaml")
testBuildFixture = exutil.FixturePath("fixtures", "test-auth-build.yaml")
oc = exutil.NewCLI("build-sti-env", exutil.KubeConfigPath())
caCertPath = filepath.Join(filepath.Dir(exutil.KubeConfigPath()), "ca.crt")
)
g.JustBeforeEach(func() {
g.By("waiting for builder service account")
err := exutil.WaitForBuilderAccount(oc.KubeREST().ServiceAccounts(oc.Namespace()))
o.Expect(err).NotTo(o.HaveOccurred())
})
g.Describe("Build using a username, password, and CA certificate", func() {
g.It("should create a new build using the internal gitserver", func() {
oc.SetOutputDir(exutil.TestContext.OutputDir)
g.By("obtaining the configured API server host from config")
adminClientConfig, err := testutil.GetClusterAdminClientConfig(exutil.KubeConfigPath())
o.Expect(err).NotTo(o.HaveOccurred())
hostURL, err := url.Parse(adminClientConfig.Host)
o.Expect(err).NotTo(o.HaveOccurred())
host, err := hostname(hostURL.Host)
o.Expect(err).NotTo(o.HaveOccurred())
routeSuffix := fmt.Sprintf("%s.%s", host, hostNameSuffix)
g.By(fmt.Sprintf("calling oc new-app -f %q -p ROUTE_SUFFIX=%s", gitServerFixture, routeSuffix))
err = oc.Run("new-app").Args("-f", gitServerFixture, "-p", fmt.Sprintf("ROUTE_SUFFIX=%s", routeSuffix)).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("expecting the deployment of the gitserver to be in the Complete phase")
err = exutil.WaitForADeployment(oc.KubeREST().ReplicationControllers(oc.Namespace()), gitServerDeploymentConfigName,
exutil.CheckDeploymentCompletedFunc, exutil.CheckDeploymentFailedFunc)
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("creating a new secret for the gitserver by calling oc secrets new-basicauth %s --username=%s --password=%s --cacert=%s",
sourceSecretName, gitUserName, gitPassword, caCertPath))
err = oc.Run("secrets").
Args("new-basicauth", sourceSecretName,
fmt.Sprintf("--username=%s", gitUserName),
fmt.Sprintf("--password=%s", gitPassword),
fmt.Sprintf("--ca-cert=%s", caCertPath)).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
sourceURL := fmt.Sprintf(sourceURLTemplate, routeSuffix)
g.By(fmt.Sprintf("creating a new BuildConfig by calling oc new-app -f %q -p SOURCE_SECRET=%s,SOURCE_URL=%s",
testBuildFixture, sourceSecretName, sourceURL))
err = oc.Run("new-app").Args("-f", testBuildFixture, "-p", fmt.Sprintf("SOURCE_SECRET=%s,SOURCE_URL=%s",
sourceSecretName, sourceURL)).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("starting a test build")
buildName, err := oc.Run("start-build").Args(buildConfigName).Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("expecting build %s to complete successfully", buildName))
err = exutil.WaitForABuild(oc.REST().Builds(oc.Namespace()), buildName, exutil.CheckBuildSuccessFunc, exutil.CheckBuildFailedFunc)
o.Expect(err).NotTo(o.HaveOccurred())
})
})
})