Skip to content

Commit

Permalink
fix breaking changes of hex_core
Browse files Browse the repository at this point in the history
  • Loading branch information
cgerling committed May 4, 2023
1 parent 099c74b commit 685b307
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/hex/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ defmodule Hex.Repo do
releases
else
case :mix_hex_registry.decode_package(body, repo, package) do
{:ok, releases} ->
{:ok, %{releases: releases}} ->
outer_checksum? = Enum.all?(releases, &Map.has_key?(&1, :outer_checksum))

if not outer_checksum? and Hex.Server.should_warn_registry_version?() do
Expand Down
14 changes: 12 additions & 2 deletions test/hex/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,18 @@ defmodule Hex.RepoTest do
end)

Hex.State.put(:no_verify_repo_origin, true)
assert Hex.Repo.decode_package(message, "other repo", "ecto") == []
assert Hex.Repo.decode_package(message, "hexpm", "other package") == []

assert Hex.Repo.decode_package(message, "other repo", "ecto") == %{
name: "ecto",
releases: [],
repository: "hexpm"
}

assert Hex.Repo.decode_package(message, "hexpm", "other package") == %{
name: "ecto",
releases: [],
repository: "hexpm"
}
end

test "get public key" do
Expand Down
32 changes: 22 additions & 10 deletions test/mix/tasks/hex.registry_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ defmodule Mix.Tasks.Hex.RegistryTest do
repo_verify_origin: false
}

assert {:ok, {200, _, []}} = :mix_hex_repo.get_names(config)
assert {:ok, {200, _, []}} = :mix_hex_repo.get_versions(config)
assert {:ok, {200, _, %{packages: []}}} = :mix_hex_repo.get_names(config)
assert {:ok, {200, _, %{packages: []}}} = :mix_hex_repo.get_versions(config)

{:ok, %{tarball: tarball}} = :mix_hex_tarball.create(%{name: "foo", version: "0.10.0"}, [])
File.write!("public/tarballs/foo-0.10.0.tar", tarball)
Expand All @@ -45,7 +45,7 @@ defmodule Mix.Tasks.Hex.RegistryTest do
refute_received _

assert {:ok, {200, _, names}} = :mix_hex_repo.get_names(config)
assert [%{name: "foo", updated_at: %{seconds: updated_at}}] = names
assert %{packages: [%{name: "foo", updated_at: %{seconds: updated_at}}]} = names

assert updated_at ==
"public/tarballs/foo-0.10.0.tar"
Expand All @@ -54,7 +54,11 @@ defmodule Mix.Tasks.Hex.RegistryTest do
|> Mix.Tasks.Hex.Registry.to_unix()

assert {:ok, {200, _, versions}} = :mix_hex_repo.get_versions(config)
assert versions == [%{name: "foo", retired: [], versions: ["0.10.0"]}]

assert versions == %{
packages: [%{name: "foo", retired: [], versions: ["0.10.0"]}],
repository: "acme"
}

{:ok, %{tarball: tarball}} = :mix_hex_tarball.create(%{name: "foo", version: "0.9.0"}, [])
File.write!("public/tarballs/foo-0.9.0.tar", tarball)
Expand All @@ -72,7 +76,7 @@ defmodule Mix.Tasks.Hex.RegistryTest do
refute_received _

assert {:ok, {200, _, names}} = :mix_hex_repo.get_names(config)
assert [%{name: "foo", updated_at: %{seconds: updated_at}}] = names
assert %{packages: [%{name: "foo", updated_at: %{seconds: updated_at}}]} = names

assert updated_at ==
"public/tarballs/foo-0.9.0.tar"
Expand All @@ -81,7 +85,11 @@ defmodule Mix.Tasks.Hex.RegistryTest do
|> Mix.Tasks.Hex.Registry.to_unix()

assert {:ok, {200, _, versions}} = :mix_hex_repo.get_versions(config)
assert versions == [%{name: "foo", retired: [], versions: ["0.9.0", "0.10.0"]}]

assert versions == %{
packages: [%{name: "foo", retired: [], versions: ["0.9.0", "0.10.0"]}],
repository: "acme"
}

# Versions with hyphen
{:ok, %{tarball: tarball}} =
Expand All @@ -102,9 +110,13 @@ defmodule Mix.Tasks.Hex.RegistryTest do
refute_received _

assert {:ok, {200, _, names}} = :mix_hex_repo.get_names(config)
assert [%{name: "foo", updated_at: _}] = names
assert %{packages: [%{name: "foo", updated_at: _}]} = names
assert {:ok, {200, _, versions}} = :mix_hex_repo.get_versions(config)
assert versions == [%{name: "foo", retired: [], versions: ["0.9.0", "0.10.0", "1.0.0-rc"]}]

assert versions == %{
packages: [%{name: "foo", retired: [], versions: ["0.9.0", "0.10.0", "1.0.0-rc"]}],
repository: "acme"
}

# Re-generating private key
0 = Mix.shell().cmd("openssl genrsa -out private_key.pem")
Expand Down Expand Up @@ -160,8 +172,8 @@ defmodule Mix.Tasks.Hex.RegistryTest do
refute_received _

assert {:ok, {200, _, names}} = :mix_hex_repo.get_names(config)
assert [%{name: "bar", updated_at: _}, %{name: "foo", updated_at: _}] = names
assert {:ok, {200, _, [package]}} = :mix_hex_repo.get_package(config, "bar")
assert %{packages: [%{name: "bar", updated_at: _}, %{name: "foo", updated_at: _}]} = names
assert {:ok, {200, _, %{releases: [package]}}} = :mix_hex_repo.get_package(config, "bar")

assert package.dependencies == [
%{
Expand Down

0 comments on commit 685b307

Please sign in to comment.