diff options
author | Robert Newson <rnewson@apache.org> | 2020-03-19 16:03:16 +0000 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2020-03-22 23:16:29 +0000 |
commit | bb86d0478412e525e810abbb4cecbdd32c6d3e11 (patch) | |
tree | 2c38f52bca2ecb027152c722272376810d5ba6ce | |
parent | 8074a32f173b683a902d5c5f92115d434b3be262 (diff) | |
download | couchdb-bb86d0478412e525e810abbb4cecbdd32c6d3e11.tar.gz |
generate JWT token ourselves
-rw-r--r-- | mix.exs | 2 | ||||
-rw-r--r-- | test/elixir/test/jwtauth_test.exs | 9 |
2 files changed, 7 insertions, 4 deletions
@@ -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.1", only: [:dev, :test, :integration], runtime: false} diff --git a/test/elixir/test/jwtauth_test.exs b/test/elixir/test/jwtauth_test.exs index 2e78ee989..9f2074ccf 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", "couch@apache.org"}]}, key) resp = Couch.get("/_session", - headers: [authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJjb3VjaEBhcGFjaGUub3JnIn0.KYHmGXWj0HNHzZCjfOfsIfZWdguEBSn31jUdDUA9118"] + headers: [authorization: "Bearer #{token}"] ) assert resp.body["userCtx"]["name"] == "couch@apache.org" |