This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch jwt-enhancements
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bc26126f94581317e1594adda8d61147ac530f1f
Author: Robert Newson <[email protected]>
AuthorDate: Thu Mar 19 16:03:16 2020 +0000

    generate JWT token ourselves
---
 mix.exs                           | 2 ++
 test/elixir/test/jwtauth_test.exs | 9 +++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/mix.exs b/mix.exs
index bd78c30..4d0132f 100644
--- a/mix.exs
+++ b/mix.exs
@@ -65,7 +65,9 @@ defmodule CouchDBTest.Mixfile do
       {:junit_formatter, "~> 3.0", only: [:dev, :test, :integration]},
       {:httpotion, ">= 3.1.3", only: [:dev, :test, :integration], runtime: 
false},
       {:excoveralls, "~> 0.12", only: :test},
+      {:b64url, path: Path.expand("src/b64url", __DIR__)},
       {:jiffy, path: Path.expand("src/jiffy", __DIR__)},
+      {:jwtf, path: Path.expand("src/jwtf", __DIR__)},
       {:ibrowse,
        path: Path.expand("src/ibrowse", __DIR__), override: true, compile: 
false},
       {:credo, "~> 1.3.0", only: [:dev, :test, :integration], runtime: false}
diff --git a/test/elixir/test/jwtauth_test.exs 
b/test/elixir/test/jwtauth_test.exs
index 2e78ee9..9f2074c 100644
--- a/test/elixir/test/jwtauth_test.exs
+++ b/test/elixir/test/jwtauth_test.exs
@@ -3,7 +3,7 @@ defmodule JwtAuthTest do
 
   @moduletag :authentication
 
-  test "jwt auth with secret", _context do
+  test "jwt auth with HS256 secret", _context do
 
     secret = "zxczxc12zxczxc12"
 
@@ -16,13 +16,14 @@ defmodule JwtAuthTest do
     ]
 
     run_on_modified_server(server_config, fn ->
-      test_fun()
+      test_fun("HS256", secret)
     end)
   end
 
-  def test_fun() do
+  def test_fun(alg, key) do
+    {:ok, token} = :jwtf.encode({[{"alg", alg}, {"typ", "JWT"}]}, {[{"sub", 
"[email protected]"}]}, key)
     resp = Couch.get("/_session",
-      headers: [authorization: "Bearer 
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjb3VjaEBhcGFjaGUub3JnIn0.KYHmGXWj0HNHzZCjfOfsIfZWdguEBSn31jUdDUA9118"]
+      headers: [authorization: "Bearer #{token}"]
     )
 
     assert resp.body["userCtx"]["name"] == "[email protected]"

Reply via email to