Skip to content

Commit

Permalink
always load the openssl extension
Browse files Browse the repository at this point in the history
This should fix potentially missing openssl extensions (reported in paketo-buildpacks/composer#27). The fix is to always load openssl.so.
  • Loading branch information
thirdeyenick committed Dec 1, 2023
1 parent f96ce7a commit 3fc9482
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

const (
runComposerInstallOnCacheEnv = "BP_RUN_COMPOSER_INSTALL"
opensslExtension = "openssl"
)

// DetermineComposerInstallOptions defines the interface to get options for `composer install`
Expand Down Expand Up @@ -448,7 +449,7 @@ func writeComposerPhpIni(logger scribe.Emitter, context packit.BuildContext) (co

phpIni := fmt.Sprintf(`[PHP]
extension_dir = "%s"
extension = openssl.so`, os.Getenv(PhpExtensionDir))
extension = %s.so`, os.Getenv(PhpExtensionDir), opensslExtension)
logger.Debug.Subprocess("Writing php.ini contents:\n'%s'", phpIni)

return composerPhpIniPath, os.WriteFile(composerPhpIniPath, []byte(phpIni), os.ModePerm)
Expand Down Expand Up @@ -493,7 +494,12 @@ func runCheckPlatformReqs(logger scribe.Emitter, checkPlatformReqsExec Executabl
}
}

var extensions []string
// we always include the openssl extension as it will not be found
// otherwise. The reason for this is that `writeComposerPhpIni` gets
// executed first and already includes the openssl extension. `composer
// check-platform-reqs` will therefore not output a missing openssl
// extension (as it was already loaded).
var extensions = []string{opensslExtension}
for _, line := range strings.Split(buffer.String(), "\n") {
chunks := strings.Split(strings.TrimSpace(line), " ")
extensionName := strings.TrimPrefix(strings.TrimSpace(chunks[0]), "ext-")
Expand Down
5 changes: 3 additions & 2 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ composer-lock-sha = "sha-from-composer-lock"
contents, err := os.ReadFile(filepath.Join(workingDir, ".php.ini.d", "composer-extensions.ini"))
Expect(err).NotTo(HaveOccurred())

Expect(string(contents)).To(Equal(`extension = hello.so
Expect(string(contents)).To(Equal(`extension = openssl.so
extension = hello.so
extension = bar.so
`))
})
Expand Down Expand Up @@ -610,7 +611,7 @@ extension = bar.so
Expect(output).To(ContainSubstring(fmt.Sprintf("Listing files in %s:", filepath.Join(layersDir, composer.ComposerPackagesLayerName, "vendor"))))
Expect(output).To(ContainSubstring(" Generating SBOM"))
Expect(output).To(ContainSubstring("Running 'composer check-platform-reqs'"))
Expect(output).To(ContainSubstring("Found extensions 'hello, bar'"))
Expect(output).To(ContainSubstring("Found extensions 'openssl, hello, bar'"))
})
})

Expand Down
3 changes: 2 additions & 1 deletion integration/with_extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func testWithExtensions(t *testing.T, context spec.G, it spec.S) {
Expect(err).ToNot(HaveOccurred(), logs.String)

Expect(logs).To(ContainSubstring("Running 'composer check-platform-reqs'"))
Expect(logs).To(ContainSubstring("Found extensions 'fileinfo, gd, mysqli, zip'"))
Expect(logs).To(ContainSubstring("Found extensions 'openssl, fileinfo, gd, mysqli, zip'"))

container, err = docker.Container.Run.
WithEnv(map[string]string{"PORT": "8765"}).
Expand All @@ -78,6 +78,7 @@ func testWithExtensions(t *testing.T, context spec.G, it spec.S) {
// Note that `mbstring` is not included, since it is not available in `php-dist` for unknown reasons
extensionsMatcher := And(
ContainSubstring("zip"),
ContainSubstring("openssl"),
ContainSubstring("gd"),
ContainSubstring("fileinfo"),
ContainSubstring("mysqli"),
Expand Down

0 comments on commit 3fc9482

Please sign in to comment.