-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildpack_spec.rb
148 lines (118 loc) · 4.06 KB
/
buildpack_spec.rb
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
require_relative "../spec_helper.rb"
RSpec.describe "This buildpack" do
it "accepts absolute paths at build and runtime" do
app_dir = generate_fixture_app(
name: "works",
compile_script: <<~EOM
#!/usr/bin/env bash
# Test export
echo "export PATH=/good/absolute/path:$PATH" >> export
# Test .profile.d
BUILD_DIR=$1
mkdir -p $BUILD_DIR/.profile.d
echo "export PATH=/good/absolute/path:$PATH" >> $BUILD_DIR/.profile.d/my.sh
EOM
)
buildpacks = [
"https://github.com/heroku/heroku-buildpack-inline",
:default
]
Hatchet::Runner.new(app_dir, buildpacks: buildpacks).deploy do |app|
expect(app.output).to_not include("All paths must be absolute")
end
end
describe "export detection" do
it "errors on relative paths" do
app_dir = generate_fixture_app(
name: "export_fails_relative",
compile_script: <<~EOM
#!/usr/bin/env bash
echo "export PATH=bad_export_path_because_im_relative:$PATH" >> export
EOM
)
buildpacks = [
"https://github.com/heroku/heroku-buildpack-inline",
:default
]
Hatchet::Runner.new(app_dir, buildpacks: buildpacks, allow_failure: true).deploy do |app|
expect(app.output).to include("All paths must be absolute")
end
end
end
describe "profile.d detection" do
it "errors on relative paths" do
app_dir = generate_fixture_app(
name: "export_fails_relative",
compile_script: <<~EOM
#!/usr/bin/env bash
BUILD_DIR=$1
mkdir -p $BUILD_DIR/.profile.d
echo "export PATH=bad_export_path_because_im_relative:$PATH" >> $BUILD_DIR/.profile.d/my.sh
EOM
)
buildpacks = [
"https://github.com/heroku/heroku-buildpack-inline",
:default
]
Hatchet::Runner.new(app_dir, buildpacks: buildpacks, allow_failure: true).deploy do |app|
expect(app.output).to include("All paths must be absolute")
end
end
end
describe "leaky build path detection" do
it "errors on leaky paths" do
app_dir = generate_fixture_app(
name: "leaky_build_path",
compile_script: <<~EOM
#!/usr/bin/env bash
BUILD_DIR=$1
mkdir -p $BUILD_DIR/.profile.d
echo "export PATH=$BUILD_DIR/foo:$PATH" >> $BUILD_DIR/.profile.d/my.sh
EOM
)
buildpacks = [
"https://github.com/heroku/heroku-buildpack-inline",
:default
]
Hatchet::Runner.new(app_dir, buildpacks: buildpacks, allow_failure: true).deploy do |app|
expect(app.output).to include("A build path leaked into runtime")
end
end
end
describe "ignoring keys" do
it "doesn't raise at build" do
app_dir = generate_fixture_app(
name: "ignore_path_build",
compile_script: <<~EOM
#!/usr/bin/env bash
echo "export IGNORE_THIS_PATH=bad_export_path_because_im_relative" >> export
EOM
)
buildpacks = [
"https://github.com/heroku/heroku-buildpack-inline",
:default
]
Hatchet::Runner.new(app_dir, buildpacks: buildpacks, config: { FORCE_ABSOLUTE_PATHS_BUILDPACK_IGNORE_PATHS: "IGNORE_THIS_PATH"}).deploy do |app|
expect(app.output).to include("Ignoring key IGNORE_THIS_PATH")
end
end
it "doesn't raise at runtime" do
app_dir = generate_fixture_app(
name: "ignore_path_runtime",
compile_script: <<~EOM
#!/usr/bin/env bash
BUILD_DIR=$1
mkdir -p $BUILD_DIR/.profile.d
echo "export IGNORE_THIS_PATH=bad_path_because_relativ" >> $BUILD_DIR/.profile.d/my.sh
EOM
)
buildpacks = [
"https://github.com/heroku/heroku-buildpack-inline",
:default
]
Hatchet::Runner.new(app_dir, buildpacks: buildpacks, allow_failure: true, config: { FORCE_ABSOLUTE_PATHS_BUILDPACK_IGNORE_PATHS: "IGNORE_THIS_PATH"}).deploy do |app|
expect(app.output).to include("Ignoring key IGNORE_THIS_PATH")
end
end
end
end