Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F115777
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c49c78a..bebb05d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,61 +1,62 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog][1], and this project adheres to [Semantic Versioning][2].
[1]: https://keepachangelog.com/en/1.0.0/
[2]: https://semver.org/spec/v2.0.0.html
## majic [Unreleased]
## Added
- Forked gen_magic.
- Pool: `Majic.Pool`
+- Plug: `Majic.Plug`
- Unified API: `Majic.perform/1,2,3`
## Changed
- C port now using erl_interface
- Builds on Musl
- Better error and timeout handling
- `Majic.Server.reload/2,3`
- `Majic.Server.recycle/2,3`
- Bytes support: `Majic.Server.perform(ref, {:bytes, <<>>})`
- Renamed `priv/apprentice` to `priv/libmagic_port` to be more obvious in `ps`
- Renamed `Majic.Helpers.perform_once` to `Majic.Once.perform`
## gen_majic [1.0]
### Added
- Added support for process recycling (evadne).
- Added documentation (evadne).
### Changed
- Replaced GenServer with `:gen_statem` (evadne).
- Changed API; added support for customisation.
- Refined tests and other aspects of the library (evadne).
## [0.20.83]
### Added
- Soak testing script (devstopfix)
### Changed
- Replaced Erlexec usage with Port (devstopfix)
## 0.0.1
### Added
- Initial Elixir wrapper with Erlexec (evadne)
- Intiial C program (evadne)
[unreleased]: https://github.com/evadne/gen_magic/compare/develop
[0.20.83]: https://github.com/devstopfix/gen_magic/commit/7e27fd094cb462d26ba54fde0205a5be313d12da
diff --git a/test/builds-sr-ht.exs b/test/builds-sr-ht.exs
new file mode 100644
index 0000000..7f7c7f8
--- /dev/null
+++ b/test/builds-sr-ht.exs
@@ -0,0 +1,52 @@
+name =
+ case System.cmd("git", ~w(describe --all --long --dirty --broken --always)) do
+ {name, 0} -> String.trim(name)
+ _ -> "cannot-git-describe"
+ end
+
+repo = System.get_env("TEST_REPO") || "https://git.sr.ht/~href/gen_magic"
+
+IO.puts("Using repository: #{repo}")
+
+token = System.get_env("SR_HT_TOKEN")
+
+unless token do
+ IO.puts("""
+ sr.ht token not defined (SR_HT_TOKEN)\n\n
+ Get one at https://meta.sr.ht/oauth/personal-token\n
+ Define one by setting the SR_HT_TOKEN environment variable
+ """)
+else
+ Application.ensure_all_started(:ssl)
+ Application.ensure_all_started(:inets)
+
+ File.ls!(".builds")
+ |> Enum.filter(fn file -> Path.extname(file) == ".yaml" end)
+ |> Enum.each(fn file ->
+ file = Path.join(".builds", file)
+ build = Path.basename(file, ".yaml")
+
+ build =
+ %{
+ "manifest" => File.read!(file),
+ "note" => "gen_magic/#{name} #{build}",
+ "tags" => ["gen_magic"]
+ }
+ |> Jason.encode!()
+
+ case :httpc.request(
+ :post,
+ {'https://builds.sr.ht/api/jobs', [{'authorization', 'token ' ++ to_charlist(token)}],
+ 'application/json', build},
+ [],
+ []
+ ) do
+ {:ok, {{_http_v, 200, 'OK'}, _headers, body}} ->
+ resp = Jason.decode!(body)
+ IO.puts("#{resp["status"]} job #{resp["note"]}, id: #{resp["id"]}")
+
+ error ->
+ IO.puts("Failed to enqueue job #{inspect(error)}")
+ end
+ end)
+end
diff --git a/test/majic/plug_test.exs b/test/majic/plug_test.exs
index a850cb5..63c2dd9 100644
--- a/test/majic/plug_test.exs
+++ b/test/majic/plug_test.exs
@@ -1,72 +1,84 @@
defmodule Majic.PlugTest do
use ExUnit.Case, async: true
use Plug.Test
defmodule TestRouter do
use Plug.Router
- plug :match
- plug :dispatch
- plug Plug.Parsers,
+ plug(:match)
+ plug(:dispatch)
+
+ plug(Plug.Parsers,
parsers: [:urlencoded, :multipart],
pass: ["*/*"]
- #plug Majic.Plug, once: true
+ )
+
+ # plug Majic.Plug, once: true
post "/" do
send_resp(conn, 200, "Ok")
end
end
setup_all do
Application.ensure_all_started(:plug)
:ok
end
@router_opts TestRouter.init([])
test "convert uploads" do
multipart = """
------w58EW1cEpjzydSCq\r
Content-Disposition: form-data; name=\"form[makefile]\"; filename*=\"utf-8''mymakefile.txt\"\r
Content-Type: text/plain\r
\r
#{String.replace(File.read!("Makefile"), "\n", "\n")}\r
------w58EW1cEpjzydSCq\r
Content-Disposition: form-data; name=\"form[make][file]\"; filename*=\"utf-8''mymakefile.txt\"\r
Content-Type: text/plain\r
\r
#{String.replace(File.read!("Makefile"), "\n", "\n")}\r
------w58EW1cEpjzydSCq\r
Content-Disposition: form-data; name=\"cat\"; filename*=\"utf-8''cute-cat.jpg\"\r
Content-Type: image/jpg\r
\r
#{String.replace(File.read!("test/fixtures/cat.webp"), "\n", "\n")}\r
------w58EW1cEpjzydSCq--\r
"""
- orig_conn = conn(:post, "/", multipart)
- |> put_req_header("content-type", "multipart/mixed; boundary=----w58EW1cEpjzydSCq")
- |> TestRouter.call(@router_opts)
+ orig_conn =
+ conn(:post, "/", multipart)
+ |> put_req_header("content-type", "multipart/mixed; boundary=----w58EW1cEpjzydSCq")
+ |> TestRouter.call(@router_opts)
- plug = Majic.Plug.init([once: true])
- plug_no_ext = Majic.Plug.init([once: true, fix_extension: false])
- plug_append_ext = Majic.Plug.init([once: true, fix_extension: true, append_extension: true])
+ plug = Majic.Plug.init(once: true)
+ plug_no_ext = Majic.Plug.init(once: true, fix_extension: false)
+ plug_append_ext = Majic.Plug.init(once: true, fix_extension: true, append_extension: true)
conn = Majic.Plug.call(orig_conn, plug)
conn_no_ext = Majic.Plug.call(orig_conn, plug_no_ext)
conn_append_ext = Majic.Plug.call(orig_conn, plug_append_ext)
assert conn.state == :sent
assert conn.status == 200
- refute get_in(conn.body_params, ["form", "makefile"]).content_type == get_in(conn.params, ["form", "makefile"]).content_type
+
+ refute get_in(conn.body_params, ["form", "makefile"]).content_type ==
+ get_in(conn.params, ["form", "makefile"]).content_type
+
assert get_in(conn.params, ["form", "makefile"]).content_type == "text/x-makefile"
- refute get_in(conn.body_params, ["form", "make", "file"]).content_type == get_in(conn.params, ["form", "make", "file"]).content_type
+
+ refute get_in(conn.body_params, ["form", "make", "file"]).content_type ==
+ get_in(conn.params, ["form", "make", "file"]).content_type
+
assert get_in(conn.params, ["form", "make", "file"]).content_type == "text/x-makefile"
- refute get_in(conn.body_params, ["cat"]).content_type == get_in(conn.params, ["cat"]).content_type
+
+ refute get_in(conn.body_params, ["cat"]).content_type ==
+ get_in(conn.params, ["cat"]).content_type
+
assert get_in(conn.params, ["cat"]).content_type == "image/webp"
assert get_in(conn.params, ["cat"]).filename == "cute-cat.webp"
assert get_in(conn_no_ext.params, ["cat"]).filename == "cute-cat.jpg"
assert get_in(conn_append_ext.params, ["cat"]).filename == "cute-cat.jpg.webp"
end
-
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Nov 29, 12:36 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41122
Default Alt Text
(6 KB)
Attached To
Mode
R20 majic
Attached
Detach File
Event Timeline
Log In to Comment