Skip to content

Commit 5083304

Browse files
authored
CI and docs housekeeping (#40)
List of changes: - add changelog link to hex module view - bump actions/checkout and actions/cache - bump ex_doc and related deps - improve test coverage - remove deprecated code since we're on OTP 24 - set minimal Elixir requirement to 1.13 - support Elixir 1.19/OTP 28 in CI matrix
1 parent 4dbad7d commit 5083304

5 files changed

Lines changed: 53 additions & 22 deletions

File tree

.github/workflows/main.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-22.04
1212
env:
1313
MIX_ENV: test
1414
strategy:
1515
fail-fast: false
1616
matrix:
1717
include:
1818
- pair:
19-
elixir: 1.12.0
20-
otp: 22.3
19+
elixir: "1.13"
20+
otp: "24"
2121
- pair:
22-
elixir: 1.14.1
23-
otp: 25.1
22+
elixir: "1.19"
23+
otp: "28"
2424
lint: lint
2525
steps:
26-
- uses: actions/checkout@v3
26+
- uses: actions/checkout@v5
2727

2828
- uses: erlef/setup-beam@v1
2929
with:
3030
otp-version: ${{matrix.pair.otp}}
3131
elixir-version: ${{matrix.pair.elixir}}
3232

33-
- uses: actions/cache@v3
33+
- uses: actions/cache@v4
3434
with:
3535
path: |
3636
deps

lib/nimble_totp.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,7 @@ defmodule NimbleTOTP do
258258
hmac_sha(secret, moving_factor)
259259
end
260260

261-
# TODO: Remove me when we require OTP 22.1
262-
if Code.ensure_loaded?(:crypto) and function_exported?(:crypto, :mac, 4) do
263-
defp hmac_sha(key, data), do: :crypto.mac(:hmac, :sha, key, data)
264-
else
265-
defp hmac_sha(key, data), do: :crypto.hmac(:sha, key, data)
266-
end
261+
defp hmac_sha(key, data), do: :crypto.mac(:hmac, :sha, key, data)
267262

268263
defp hmac_truncate(hmac) do
269264
<<_::19-binary, _::4, offset::4>> = hmac

mix.exs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule NimbleTOTP.MixProject do
88
[
99
app: :nimble_totp,
1010
version: @version,
11-
elixir: "~> 1.12",
11+
elixir: "~> 1.13",
1212
start_permanent: Mix.env() == :prod,
1313
deps: deps(),
1414

@@ -30,14 +30,17 @@ defmodule NimbleTOTP.MixProject do
3030

3131
defp deps do
3232
[
33-
{:ex_doc, ">= 0.19.0", only: :docs}
33+
{:ex_doc, ">= 0.0.0", only: :docs}
3434
]
3535
end
3636

3737
defp package do
3838
[
3939
licenses: ["Apache-2.0"],
40-
links: %{"GitHub" => @repo_url}
40+
links: %{
41+
"GitHub" => @repo_url,
42+
"Changelog" => "#{@repo_url}/blob/main/CHANGELOG.md"
43+
}
4144
]
4245
end
4346

mix.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
%{
2-
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
3-
"ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"},
4-
"makeup": {:hex, :makeup, "1.2.0", "b92e9476c62534bd0e5ea9b9fcf36536ca929b6842549832c71d2533cdbe72f7", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "a7af3614f63cbfde2bbe5823cb3e5369317feca391c3a1f96dab8b6b8b09fdf9"},
5-
"makeup_elixir": {:hex, :makeup_elixir, "1.0.0", "74bb8348c9b3a51d5c589bf5aebb0466a84b33274150e3b6ece1da45584afc82", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "49159b7d7d999e836bedaf09dcf35ca18b312230cf901b725a64f3f42e407983"},
6-
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
7-
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
2+
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
3+
"ex_doc": {:hex, :ex_doc, "0.39.1", "e19d356a1ba1e8f8cfc79ce1c3f83884b6abfcb79329d435d4bbb3e97ccc286e", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "8abf0ed3e3ca87c0847dfc4168ceab5bedfe881692f1b7c45f4a11b232806865"},
4+
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
5+
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
6+
"makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"},
7+
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
88
}

test/nimble_totp_test.exs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ defmodule NimbleTOTPTest do
4444
extra=extra%20value\
4545
"""
4646
end
47+
48+
test "Generate the uri with extra params (deprecated, with digits option)" do
49+
secret = Base.decode32!("PTEPUGZ7DUWTBGMW4WLKB6U63MGKKMCA")
50+
app = "Bytepack App"
51+
52+
assert NimbleTOTP.otpauth_uri("#{app}:user@test.com", secret, issuer: app, digits: 8) == """
53+
otpauth://totp/Bytepack%20App:user@test.com?\
54+
secret=PTEPUGZ7DUWTBGMW4WLKB6U63MGKKMCA&\
55+
issuer=Bytepack%20App&\
56+
digits=8\
57+
"""
58+
end
59+
60+
test "raises error if issuer contains a colon (otpauth_uri/4)" do
61+
secret = Base.decode32!("PTEPUGZ7DUWTBGMW4WLKB6U63MGKKMCA")
62+
63+
assert_raise ArgumentError, "issuer cannot have :", fn ->
64+
NimbleTOTP.otpauth_uri("Acme:Inc", "alice", secret, [])
65+
end
66+
end
67+
68+
test "raises error if account contains a colon (otpauth_uri/4)" do
69+
secret = Base.decode32!("PTEPUGZ7DUWTBGMW4WLKB6U63MGKKMCA")
70+
71+
assert_raise ArgumentError, "account cannot have :", fn ->
72+
NimbleTOTP.otpauth_uri("Acme", "alice:corp", secret, [])
73+
end
74+
end
4775
end
4876

4977
describe "secret" do
@@ -204,6 +232,11 @@ defmodule NimbleTOTPTest do
204232
NimbleTOTP.verification_code(secret, time: time, digits: 11)
205233
end
206234
end
235+
236+
test "returns false if the otp is not a binary" do
237+
secret = NimbleTOTP.secret()
238+
refute NimbleTOTP.valid?(secret, 123_456, time: System.os_time(:second))
239+
end
207240
end
208241

209242
defp to_unix(naive_datetime),

0 commit comments

Comments
 (0)