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
24 changes: 24 additions & 0 deletions internal/validate/embed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package validate

import (
"os"
"strings"
"testing"
)

// Both ways of building rc embed the core schema through linker flags: scripts/build.go for local
// and CI builds, scripts/release-package.py for the release archives and packages. The release
// build once set only the Go profiler's variable, so a released rc refused to validate. CI builds
// with build.go only, so nothing else would notice that again.
func TestEveryBuildEmbedsTheCoreSchemaInTheValidator(t *testing.T) {
const variable = "github.com/runtimeconditions/rc-cli/internal/validate.coreSchemaBase64"
for _, script := range []string{"../../scripts/build.go", "../../scripts/release-package.py"} {
data, err := os.ReadFile(script)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(data), variable) {
t.Errorf("%s does not set %s, so a build made with it cannot validate profiles", script, variable)
}
}
}
7 changes: 5 additions & 2 deletions scripts/release-package.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ def main():
env = dict(os.environ, CGO_ENABLED="0", GOOS=goos, GOARCH=goarch)
binary = work / target / "bin/rc"
binary.parent.mkdir(parents=True)
# The core schema is embedded twice: for the linked Go profiler and for rc's own validator.
# scripts/build.go sets the same two variables.
encoded_schema = base64.b64encode(core_schema).decode("ascii")
linker_flags = "-X main.version=" + args.version + " -X main.commit=" + args.commit + \
" -X github.com/runtimeconditions/go-rc-profiler/extensioncheck.installedCoreSchemaBase64=" + \
base64.b64encode(core_schema).decode("ascii")
" -X github.com/runtimeconditions/go-rc-profiler/extensioncheck.installedCoreSchemaBase64=" + encoded_schema + \
" -X github.com/runtimeconditions/rc-cli/internal/validate.coreSchemaBase64=" + encoded_schema
run(["go", "build", "-trimpath", "-buildvcs=false", "-ldflags", linker_flags,
"-o", str(binary), "./cmd/rc"], env=env)
prefix = work / target / "prefix"
Expand Down
Loading