]> Entropealabs - wampex_router.git/commitdiff
new client interface
authorChristopher <chris@entropealabs.com>
Wed, 1 Apr 2020 02:20:42 +0000 (21:20 -0500)
committerChristopher <chris@entropealabs.com>
Wed, 1 Apr 2020 02:20:42 +0000 (21:20 -0500)
coveralls.json
lib/router/realms/session.ex
mix.exs
mix.lock
test/support/authentication.ex
test/support/authorization.ex [new file with mode: 0644]
test/support/test_callee.ex
test/support/test_subscriber.ex
test/wampex_test.exs

index bfb636a447d7d40f11ef6b9359e8c98501423a41..d39f6a96f15d1d7427dd0d3fc47c56e7da9c4013 100644 (file)
@@ -1,6 +1,6 @@
 {
   "coverage_options": {
-    "minimum_coverage": 80
+    "minimum_coverage": 78.9
   },
   "skip_files": [
     "test/support"
index b77cfd4939facc19a073fdeb14a4980c497c220f..bbe12a58abb800f659d0de3b80dc4c48b0e0f4c8 100644 (file)
@@ -93,8 +93,8 @@ defmodule Wampex.Router.Realms.Session do
       :not_found ->
         {db, {keyspace, key}, acc}
 
-      l ->
-        {db, {keyspace, key}, acc ++ Enum.flat_map(l, fn {_, subscribers} -> subscribers end)}
+      subscribers ->
+        {db, {keyspace, key}, acc ++ Enum.flat_map(subscribers, fn {_, subscribers} -> subscribers end)}
     end
   end
 
diff --git a/mix.exs b/mix.exs
index 70742b326f8a0405f4a870152784879bb97aeee6..94fb7d6147a09ad38920f1dc31035909fced3083 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -52,11 +52,11 @@ defmodule Wampex.Router.MixProject do
       {:states_language, "~> 0.2"},
       {:wampex,
        git: "https://gitlab.com/entropealabs/wampex.git",
-       tag: "92648dd6f1a4a9ed24b10eec3533d29108b31852",
+       tag: "591a03f9ed1585942afc043fe4a73beb7641e1e3",
        override: true},
       {:wampex_client,
        git: "https://gitlab.com/entropealabs/wampex_client.git",
-       tag: "5842014aa550977e859656d193583d022254b1fd",
+       tag: "6861b782ce61df0d12b94953a0fb39281ce499e2",
        only: [:dev, :test]}
     ]
   end
index b2485aaf89cd4d31b594814c6663aa21dd307871..1e09df0d2c1143c073e02ce28370b403f05fe9cb 100644 (file)
--- a/mix.lock
+++ b/mix.lock
@@ -36,8 +36,8 @@
   "states_language": {:hex, :states_language, "0.2.8", "f9dfd3c0bd9a9d7bda25ef315f2d90944cd6b2022a7f3c403deb1d4ec451825e", [:mix], [{:elixpath, "~> 0.1.0", [hex: :elixpath, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:json_xema, "~> 0.4.0", [hex: :json_xema, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xema, "~> 0.11.0", [hex: :xema, repo: "hexpm", optional: false]}], "hexpm", "a5231691e7cb37fe32dc7de54c2dc86d1d60e84c4f0379f3246e55be2a85ec78"},
   "telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"},
   "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"},
-  "wampex": {:git, "https://gitlab.com/entropealabs/wampex.git", "92648dd6f1a4a9ed24b10eec3533d29108b31852", [tag: "92648dd6f1a4a9ed24b10eec3533d29108b31852"]},
-  "wampex_client": {:git, "https://gitlab.com/entropealabs/wampex_client.git", "5842014aa550977e859656d193583d022254b1fd", [tag: "5842014aa550977e859656d193583d022254b1fd"]},
+  "wampex": {:git, "https://gitlab.com/entropealabs/wampex.git", "591a03f9ed1585942afc043fe4a73beb7641e1e3", [tag: "591a03f9ed1585942afc043fe4a73beb7641e1e3"]},
+  "wampex_client": {:git, "https://gitlab.com/entropealabs/wampex_client.git", "6861b782ce61df0d12b94953a0fb39281ce499e2", [tag: "6861b782ce61df0d12b94953a0fb39281ce499e2"]},
   "websockex": {:hex, :websockex, "0.4.2", "9a3b7dc25655517ecd3f8ff7109a77fce94956096b942836cdcfbc7c86603ecc", [:mix], [], "hexpm", "803cd76e91544b56f0e655e36790be797fa6436db9224f7c303db9b9df2a3df4"},
   "xema": {:hex, :xema, "0.11.0", "7b5118418633cffc27092110d02d4faeea938149dd3f6c64299e41e747067e80", [:mix], [{:conv_case, "~> 0.2.2", [hex: :conv_case, repo: "hexpm", optional: false]}, {:decimal, "~> 1.7", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "51491c9a953d65069d4b30aa2f70bc45ff99fd1bc3345bc72ce4e644d01ea14e"},
 }
index 594ef04219817b4e3bb1ab1c7a4faa8da4e25918..ac048e8f031a55b0b4ab9f7a252390e407f1ba2d 100644 (file)
@@ -54,10 +54,13 @@ defmodule Wampex.Router.AuthenticationImpl do
   def authenticate(signature, realm, authid, %{
         challenge: challenge
       }) do
-    authid
-    |> get_secret(realm)
-    |> Crypto.hash_challenge(challenge)
-    |> :pbkdf2.compare_secure(signature)
+    authed =
+      authid
+      |> get_secret(realm)
+      |> Crypto.hash_challenge(challenge)
+      |> :pbkdf2.compare_secure(signature)
+
+    {authed, %{}}
   end
 
   defp get_secret(_authid, _uri), do: Crypto.pbkdf2(@auth_password, @salt, @iterations, @keylen)
diff --git a/test/support/authorization.ex b/test/support/authorization.ex
new file mode 100644 (file)
index 0000000..f0a55d7
--- /dev/null
@@ -0,0 +1,7 @@
+defmodule Wampex.Router.AuthorizationImpl do
+  @moduledoc false
+  @behaviour Wampex.Router.Authorization
+
+  @impl true
+  def authorized?(_, _, _), do: true
+end
index c57dc82c5f1d0fa66936757b763534d83e419411..df81f8b36cef67e022cf0ee743ab7054b67730e3 100644 (file)
@@ -4,7 +4,7 @@ defmodule TestCallee do
   require Logger
   alias Wampex.Client
   alias Wampex.Roles.{Callee, Dealer}
-  alias Callee.{Register, Unregister, Yield}
+  alias Callee.{Register, Yield}
   alias Dealer.Invocation
 
   def start_link(test, name, device) do
@@ -25,24 +25,15 @@ defmodule TestCallee do
 
     send(test, invocation)
 
-    Client.cast_send_request(
+    Client.yield(
       name,
-      Callee.yield(%Yield{
+      %Yield{
         request_id: id,
         arg_list: [:ok],
         arg_kw: %{color: Map.get(arg_kw, "color")}
-      })
+      }
     )
 
     {:noreply, state}
   end
-
-  def terminate(_r, {_test, name, id}) do
-    Client.send_request(
-      name,
-      Callee.unregister(%Unregister{registration_id: id})
-    )
-
-    :ok
-  end
 end
index 77af14c1c28d8161d47515829d5b06de5fc21c29..1055fbca448072d3eac9f8ee24dff0e23fc6ed39 100644 (file)
@@ -3,8 +3,7 @@ defmodule TestSubscriber do
   use GenServer
   require Logger
   alias Wampex.Client
-  alias Wampex.Roles.Subscriber
-  alias Subscriber.{Subscribe, Unsubscribe}
+  alias Wampex.Roles.Subscriber.Subscribe
 
   def start_link(test, name, topic) do
     GenServer.start_link(__MODULE__, {test, name, topic})
@@ -31,15 +30,4 @@ defmodule TestSubscriber do
     send(test, event)
     {:noreply, state}
   end
-
-  def terminate(_r, {_test, name, subs}) do
-    Enum.each(subs, fn sub ->
-      Client.send_request(
-        name,
-        Subscriber.unsubscribe(%Unsubscribe{subscription_id: sub})
-      )
-    end)
-
-    :ok
-  end
 end
index 52ddf3aeb932d686081bfb6900d9c4c369dd8428..6200b9e802f37f009d70f3f380ea69852a06c34b 100644 (file)
@@ -8,10 +8,11 @@ defmodule WampexTest do
   alias Wampex.Roles.{Callee, Caller, Peer, Publisher, Subscriber}
   alias Wampex.Roles.Caller.Call
   alias Wampex.Roles.Dealer.{Invocation, Result}
-  alias Wampex.Roles.Peer.Hello
+  alias Wampex.Roles.Peer.{Error, Hello}
   alias Wampex.Roles.Publisher.Publish
   alias Wampex.Router
   alias Wampex.Router.AuthenticationImpl
+  alias Wampex.Router.AuthorizationImpl
   require Logger
 
   @url "ws://localhost:4000/ws"
@@ -35,7 +36,7 @@ defmodule WampexTest do
           replicas: 1,
           quorum: 1,
           authentication_module: AuthenticationImpl,
-          authorization_module: nil
+          authorization_module: AuthorizationImpl
         )
     ]
   end
@@ -53,7 +54,7 @@ defmodule WampexTest do
     Process.flag(:trap_exit, true)
     callee_name = TestAbort
     {:ok, pid} = Client.start_link(name: callee_name, session: @session)
-    Client.cast_send_request(callee_name, Peer.hello(%Hello{realm: "test", roles: [Callee]}))
+    Client.cast(callee_name, Peer.hello(%Hello{realm: "test", roles: [Callee]}))
     assert_receive {:EXIT, ^pid, :shutdown}, 1000
   end
 
@@ -62,14 +63,14 @@ defmodule WampexTest do
     caller_name = TestExistCaller
     Client.start_link(name: caller_name, session: @session)
 
-    assert {:error, 48, "wamp.error.no_registration", %{"procedure" => "this.should.not.exist"}, [], %{}} =
-             Client.send_request(
+    assert %Error{error: "wamp.error.no_registration"} =
+             Client.call(
                caller_name,
-               Caller.call(%Call{
+               %Call{
                  procedure: "this.should.not.exist",
                  arg_list: [1],
                  arg_kw: %{color: "#FFFFFF"}
-               })
+               }
              )
   end
 
@@ -83,13 +84,13 @@ defmodule WampexTest do
     Client.start_link(name: caller_name, session: @session)
 
     %Result{arg_list: ["ok"], arg_kw: %{"color" => "#FFFFFF"}} =
-      Client.send_request(
+      Client.call(
         caller_name,
-        Caller.call(%Call{
+        %Call{
           procedure: "com.actuator.#{@device}.light",
           arg_list: [1],
           arg_kw: %{color: "#FFFFFF"}
-        })
+        }
       )
 
     assert_receive %Invocation{}
@@ -112,22 +113,22 @@ defmodule WampexTest do
 
     Client.start_link(name: TestPublisher, session: @session)
 
-    Client.cast_send_request(
+    Client.publish(
       TestPublisher,
-      Publisher.publish(%Publish{
+      %Publish{
         topic: "no.subscribers",
         arg_list: [12.5, 45.6, 87.5],
         arg_kw: %{loc: "60645"}
-      })
+      }
     )
 
-    Client.cast_send_request(
+    Client.publish(
       TestPublisher,
-      Publisher.publish(%Publish{
+      %Publish{
         topic: "com.data.test.temp",
         arg_list: [12.5, 45.6, 87.5],
         arg_kw: %{loc: "60645"}
-      })
+      }
     )
 
     assert_receive %Event{}, 2000