Skip to content

Commit cef6e86

Browse files
committed
Check the init and last options better
Previously, atoms that weren't valid applications could get through the check. This catches them and adds a test.
1 parent d5e8a03 commit cef6e86

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/shoehorn/release.ex

+7-5
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ defmodule Shoehorn.Release do
2929
extra_deps = Access.get(opts, :extra_dependencies, [])
3030

3131
# Validate arguments
32-
Enum.each(init_apps, &check_app/1)
33-
Enum.each(last_apps, &check_app/1)
32+
Enum.each(init_apps, &check_app(&1, release.applications))
33+
Enum.each(last_apps, &check_app(&1, release.applications))
3434

3535
# Build dependency graph
3636
sorted_apps =
@@ -178,9 +178,11 @@ defmodule Shoehorn.Release do
178178
order_dependencies(dep_graph, rest)
179179
end
180180

181-
defp check_app(app) when is_atom(app), do: :ok
181+
defp check_app(app, applications) when is_atom(app) do
182+
applications[app] != nil or raise ReleaseError, "#{app} is not a known OTP application"
183+
end
182184

183-
defp check_app({_, _, _} = mfa) do
185+
defp check_app({_, _, _} = mfa, _applications) do
184186
raise ReleaseError, """
185187
#{inspect(mfa)} is no longer supported in the Shoehorn `:init` option.
186188
@@ -199,7 +201,7 @@ defmodule Shoehorn.Release do
199201
"""
200202
end
201203

202-
defp check_app(other) do
204+
defp check_app(other, _applications) do
203205
raise ReleaseError, """
204206
The Shoehorn `:init` option only supports atoms. #{inspect(other)}
205207
"""

test/shoehorn/release_test.exs

+11
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,15 @@ defmodule Shoehorn.ReleaseTest do
244244
iex: :none
245245
]
246246
end
247+
248+
test "bad init apps raise" do
249+
release = @example_release |> Map.put(:options, shoehorn: [init: [nil]])
250+
assert_raise ReleaseError, fn -> Release.init(release) end
251+
252+
release = @example_release |> Map.put(:options, shoehorn: [init: [:not_an_app]])
253+
assert_raise ReleaseError, fn -> Release.init(release) end
254+
255+
release = @example_release |> Map.put(:options, shoehorn: [init: [{:m, :f, :a}]])
256+
assert_raise ReleaseError, fn -> Release.init(release) end
257+
end
247258
end

0 commit comments

Comments
 (0)