Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ api = "0.5"

[[order]]

[[order.group]]
id = "paketo-buildpacks/ca-certificates"
optional = true
version = "2.3.2"

[[order.group]]
id = "paketo-community/cpython"
version = "0.7.0"
Expand Down Expand Up @@ -46,6 +51,11 @@ api = "0.5"

[[order]]

[[order.group]]
id = "paketo-buildpacks/ca-certificates"
optional = true
version = "2.3.2"

[[order.group]]
id = "paketo-community/cpython"
version = "0.7.0"
Expand Down Expand Up @@ -79,6 +89,11 @@ api = "0.5"

[[order]]

[[order.group]]
id = "paketo-buildpacks/ca-certificates"
optional = true
version = "2.3.2"

[[order.group]]
id = "paketo-community/miniconda"
version = "0.2.0"
Expand Down Expand Up @@ -108,6 +123,11 @@ api = "0.5"

[[order]]

[[order.group]]
id = "paketo-buildpacks/ca-certificates"
optional = true
version = "2.3.2"

[[order.group]]
id = "paketo-community/cpython"
version = "0.7.0"
Expand Down
88 changes: 84 additions & 4 deletions integration/conda_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package integration_test

import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -82,20 +84,98 @@ func testConda(t *testing.T, context spec.G, it spec.S) {

Expect(response.StatusCode).To(Equal(http.StatusOK))

content, err := ioutil.ReadAll(response.Body)
content, err := io.ReadAll(response.Body)
Expect(err).NotTo(HaveOccurred())
Expect(string(content)).To(ContainSubstring("Hello, world!"))

Expect(logs).To(ContainLines(ContainSubstring("CA Certificates Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Miniconda Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Conda Env Update Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Python Start Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Procfile Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Environment Variables Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Image Labels Buildpack")))

Expect(image.Buildpacks[4].Key).To(Equal("paketo-buildpacks/environment-variables"))
Expect(image.Buildpacks[4].Layers["environment-variables"].Metadata["variables"]).To(Equal(map[string]interface{}{"SOME_VARIABLE": "some-value"}))
Expect(image.Buildpacks[5].Key).To(Equal("paketo-buildpacks/environment-variables"))
Expect(image.Buildpacks[5].Layers["environment-variables"].Metadata["variables"]).To(Equal(map[string]interface{}{"SOME_VARIABLE": "some-value"}))
Expect(image.Labels["some-label"]).To(Equal("some-value"))
})

context("when using CA certificates", func() {
var client *http.Client

it.Before(func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "ca_cert_apps"))
Expect(err).NotTo(HaveOccurred())

caCert, err := os.ReadFile(filepath.Join(source, "client_certs", "ca.pem"))
Expect(err).NotTo(HaveOccurred())

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)

cert, err := tls.LoadX509KeyPair(
filepath.Join(source, "client_certs", "cert.pem"),
filepath.Join(source, "client_certs", "key.pem"))
Expect(err).NotTo(HaveOccurred())

client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS12,
},
},
}
})

it("builds a working OCI image with a start command and uses a client-side CA cert for requests", func() {
var err error
var logs fmt.Stringer

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(pythonBuildpack).
WithPullPolicy("never").
Execute(name, filepath.Join(source, "conda"))
Expect(err).NotTo(HaveOccurred())

Expect(logs).To(ContainLines(ContainSubstring("CA Certificates Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Conda Env Update Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Python Start Buildpack")))

container, err = docker.Container.Run.
WithPublish("8080").
WithEnv(map[string]string{
"PORT": "8080",
"SERVICE_BINDING_ROOT": "/bindings",
}).
WithVolume(fmt.Sprintf("%s:/bindings/ca-certificates", filepath.Join(source, "bindings"))).
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(func() string {
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
}).Should(
ContainSubstring("Added 1 additional CA certificate(s) to system truststore"),
)

request, err := http.NewRequest("GET", fmt.Sprintf("https://localhost:%s", container.HostPort("8080")), nil)
Expect(err).NotTo(HaveOccurred())

var response *http.Response
Eventually(func() error {
var err error
response, err = client.Do(request)
return err
}).Should(BeNil())
defer response.Body.Close()

Expect(response.StatusCode).To(Equal(http.StatusOK))
})
})
})
}
89 changes: 85 additions & 4 deletions integration/no_package_manager_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package integration_test

import (
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -83,7 +85,7 @@ func testNoPackageManager(t *testing.T, context spec.G, it spec.S) {
source, err = occam.Source(filepath.Join("testdata", "no_package_manager"))
Expect(err).NotTo(HaveOccurred())

Expect(ioutil.WriteFile(filepath.Join(source, "Procfile"),
Expect(os.WriteFile(filepath.Join(source, "Procfile"),
[]byte("web: python hello.py"), os.ModePerm)).
To(Succeed())

Expand All @@ -98,14 +100,15 @@ func testNoPackageManager(t *testing.T, context spec.G, it spec.S) {
Execute(name, source)
Expect(err).NotTo(HaveOccurred(), logs.String())

Expect(logs).To(ContainLines(ContainSubstring("CA Certificates Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("CPython Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Python Start Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Procfile Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Environment Variables Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Image Labels Buildpack")))

Expect(image.Buildpacks[3].Key).To(Equal("paketo-buildpacks/environment-variables"))
Expect(image.Buildpacks[3].Layers["environment-variables"].Metadata["variables"]).To(Equal(map[string]interface{}{"SOME_VARIABLE": "some-value"}))
Expect(image.Buildpacks[4].Key).To(Equal("paketo-buildpacks/environment-variables"))
Expect(image.Buildpacks[4].Layers["environment-variables"].Metadata["variables"]).To(Equal(map[string]interface{}{"SOME_VARIABLE": "some-value"}))
Expect(image.Labels["some-label"]).To(Equal("some-value"))

container, err = docker.Container.Run.Execute(image.ID)
Expand All @@ -118,5 +121,83 @@ func testNoPackageManager(t *testing.T, context spec.G, it spec.S) {
}).Should(ContainSubstring("Hello"))
})
})

context("when using CA certificates", func() {
var client *http.Client

it.Before(func() {
var err error
source, err = occam.Source(filepath.Join("testdata", "ca_cert_apps"))
Expect(err).NotTo(HaveOccurred())

caCert, err := os.ReadFile(filepath.Join(source, "client_certs", "ca.pem"))
Expect(err).NotTo(HaveOccurred())

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)

cert, err := tls.LoadX509KeyPair(
filepath.Join(source, "client_certs", "cert.pem"),
filepath.Join(source, "client_certs", "key.pem"))
Expect(err).NotTo(HaveOccurred())

client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: caCertPool,
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS12,
},
},
}
})

it("builds a working OCI image with a start command and uses a client-side CA cert for requests", func() {
var err error
var logs fmt.Stringer

image, logs, err = pack.WithNoColor().Build.
WithBuildpacks(pythonBuildpack).
WithPullPolicy("never").
Execute(name, filepath.Join(source, "no_package_manager"))
Expect(err).NotTo(HaveOccurred())

Expect(logs).To(ContainLines(ContainSubstring("CA Certificates Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("CPython Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Python Start Buildpack")))
Expect(logs).To(ContainLines(ContainSubstring("Procfile Buildpack")))

container, err = docker.Container.Run.
WithPublish("8080").
WithEnv(map[string]string{
"PORT": "8080",
"SERVICE_BINDING_ROOT": "/bindings",
}).
WithVolume(fmt.Sprintf("%s:/bindings/ca-certificates", filepath.Join(source, "bindings"))).
Execute(image.ID)
Expect(err).NotTo(HaveOccurred())

Eventually(func() string {
cLogs, err := docker.Container.Logs.Execute(container.ID)
Expect(err).NotTo(HaveOccurred())
return cLogs.String()
}).Should(
ContainSubstring("Added 1 additional CA certificate(s) to system truststore"),
)

request, err := http.NewRequest("GET", fmt.Sprintf("https://localhost:%s", container.HostPort("8080")), nil)
Expect(err).NotTo(HaveOccurred())

var response *http.Response
Eventually(func() error {
var err error
response, err = client.Do(request)
return err
}).Should(BeNil())
defer response.Body.Close()

Expect(response.StatusCode).To(Equal(http.StatusOK))
})
})
})
}
Loading