commit 545dd499ec89dc8be410376b0878b5780c34d94c
parent dad97f1bd1855765507e2d0153275f0bf29417f4
Author: srfsh <dev@srf.sh>
Date: Mon, 4 Jul 2022 14:32:32 +0200
vf: remove passphrase requirement
Diffstat:
10 files changed, 2 insertions(+), 61 deletions(-)
diff --git a/priv/repo/migrations/20211111175352_fill_vf_agent.exs b/priv/repo/migrations/20211111175352_fill_vf_agent.exs
@@ -6,7 +6,6 @@ use Ecto.Migration
type = 'per'
AND "user" IS NOT NULL
AND email IS NOT NULL
- AND pass IS NOT NULL
AND pubkeys IS NOT NULL
AND classified_as IS NULL
)
@@ -15,7 +14,6 @@ OR
type = 'org'
AND "user" IS NULL
AND email IS NULL
- AND pass IS NULL
AND pubkeys IS NULL
)
"""
@@ -33,7 +31,6 @@ def change() do
# person
add :user, :text
add :email, :citext
- add :pass, :binary
add :pubkeys, :binary
# organization
diff --git a/src/zenflows/admin/type.ex b/src/zenflows/admin/type.ex
@@ -19,9 +19,6 @@ object :mutation_admin do
@desc "The username of the user. Must be unique"
arg :user, non_null(:string)
- @desc "The plain passphrase of the user."
- arg :pass_plain, non_null(:string), name: "pass"
-
@desc "The full name/just a label of the user. Isn't unique."
arg :name, non_null(:string)
diff --git a/src/zenflows/vf/agent.ex b/src/zenflows/vf/agent.ex
@@ -18,7 +18,6 @@ alias Zenflows.VF.SpatialThing
# person
user: String.t() | nil,
email: String.t() | nil,
- pass: binary() | nil,
pubkeys: binary() | nil,
# organization
@@ -36,7 +35,6 @@ schema "vf_agent" do
# person
field :user, :string
field :email, :string
- field :pass, :binary, redact: true
field :pubkeys, :binary
# organization
diff --git a/src/zenflows/vf/person.ex b/src/zenflows/vf/person.ex
@@ -3,7 +3,6 @@ defmodule Zenflows.VF.Person do
use Zenflows.DB.Schema
-alias Zenflows.Restroom
alias Zenflows.VF.{SpatialThing, Validate}
@type t() :: %__MODULE__{
@@ -14,8 +13,6 @@ alias Zenflows.VF.{SpatialThing, Validate}
primary_location: SpatialThing.t() | nil,
user: String.t(),
email: String.t(),
- pass: binary(),
- pass_plain: String.t() | nil,
pubkeys: binary(),
pubkeys_encoded: String.t() | nil,
}
@@ -28,16 +25,14 @@ schema "vf_agent" do
belongs_to :primary_location, SpatialThing
field :user, :string
field :email, :string
- field :pass, :binary, redact: true
- field :pass_plain, :string, virtual: true, redact: true
field :pubkeys, :binary
field :pubkeys_encoded, :string, virtual: true
end
-@insert_reqr ~w[name user email pass_plain pubkeys_encoded]a
+@insert_reqr ~w[name user email pubkeys_encoded]a
@insert_cast @insert_reqr ++ ~w[image note primary_location_id]a
# TODO: Maybe add email to @update_cast as well?
-@update_cast ~w[name image note primary_location_id user pass_plain]a
+@update_cast ~w[name image note primary_location_id user]a
# insert changeset
@doc false
@@ -49,11 +44,9 @@ def chgset(params) do
|> Validate.name(:name)
|> Validate.name(:user)
|> Validate.name(:email)
- |> Validate.name(:pass_plain)
|> Validate.uri(:image)
|> Validate.note(:note)
|> check_email()
- |> hash_pass()
|> decode_pubkeys()
|> Changeset.unique_constraint(:user)
|> Changeset.unique_constraint(:name)
@@ -70,29 +63,14 @@ def chgset(schema, params) do
|> Changeset.cast(params, @update_cast)
|> Validate.name(:name)
|> Validate.name(:user)
- |> Validate.name(:pass_plain)
|> Validate.uri(:image)
|> Validate.note(:note)
|> check_email()
- |> hash_pass()
|> Changeset.unique_constraint(:user)
|> Changeset.unique_constraint(:name)
|> Changeset.assoc_constraint(:primary_location)
end
-# Hash the passphrase in the virtual field `:pass_plain` before saving
-# to the database. The hashed passphrase will be available as `:pass`
-# thereafter.
-@spec hash_pass(Changeset.t()) :: Changeset.t()
-defp hash_pass(cset) do
- if plain = Changeset.get_change(cset, :pass_plain) do
- hash = Restroom.passgen(plain)
- Changeset.put_change(cset, :pass, hash)
- else
- cset
- end
-end
-
# Validate that :email is a valid email address.
@spec check_email(Changeset.t()) :: Changeset.t()
defp check_email(cset) do
diff --git a/src/zenflows/vf/person/type.ex b/src/zenflows/vf/person/type.ex
@@ -19,10 +19,6 @@ who have no physical location.
"""
@user "Username of the agent. Implies uniqueness."
@email "Email address of the agent. Implies uniqueness."
-@pass """
-Plain passphrase of the person. It will be hashed then stored.
-The orginal, plaintext, will be discarded.
-"""
@pubkeys """
A URL-safe, Base64-encoded string of a JSON object.
"""
@@ -82,9 +78,6 @@ input_object :person_create_params do
@desc @email
field :email, non_null(:string)
- @desc @pass
- field :pass_plain, non_null(:string), name: "pass"
-
@desc @pubkeys
field :pubkeys_encoded, non_null(:string), name: "pubkeys"
end
@@ -106,9 +99,6 @@ input_object :person_update_params do
@desc @user
field :user, :string
-
- @desc @pass
- field :pass_plain, :string, name: "pass"
end
object :query_person do
diff --git a/test/admin/type.test.exs b/test/admin/type.test.exs
@@ -6,7 +6,6 @@ setup do
params: %{
admin_key: Application.fetch_env!(:zenflows, Zenflows.Admin)[:admin_key] |> Base.encode16(case: :lower),
name: Factory.str("name"),
- pass: Factory.pass_plain(),
email: "#{Factory.str("name")}@example.com",
user: Factory.str("user"),
pubkeys_encoded: Base.url_encode64(Jason.encode!(%{foobar: 1, barfoo: 2})),
@@ -20,7 +19,6 @@ test "createUser()", %{params: params} do
createUser(
adminKey: "#{params.admin_key}"
name: "#{params.name}"
- pass: "#{params.pass}"
email: "#{params.email}"
user: "#{params.user}"
pubkeys: "#{params.pubkeys_encoded}"
diff --git a/test/help/factory.ex b/test/help/factory.ex
@@ -74,12 +74,6 @@ def uri() do
uniq("schema://user@host:port/path")
end
-@doc "The plaintext passphrase used in passphrase related fields."
-@spec pass_plain :: String.t()
-def pass_plain() do
- "so secret!"
-end
-
@doc "Inserts a schema into the database with field overrides."
@spec insert!(atom(), %{required(atom()) => term()}) :: struct()
def insert!(name, attrs \\ %{}) do
@@ -219,7 +213,6 @@ def build(:person) do
primary_location: build(:spatial_thing),
user: uniq("some user"),
email: "#{uniq("user")}@example.com",
- pass: Restroom.passgen(pass_plain()),
pubkeys: Base.url_encode64(Jason.encode!(%{a: 1, b: 2, c: 3})),
}
end
diff --git a/test/vf/agent/domain.test.exs b/test/vf/agent/domain.test.exs
@@ -25,7 +25,6 @@ describe "by_id/1" do
# person
assert agent.user == per.user
assert agent.email == per.email
- assert agent.pass == per.pass
# organization
assert agent.classified_as == nil
@@ -45,7 +44,6 @@ describe "by_id/1" do
# person
assert agent.user == nil
assert agent.email == nil
- assert agent.pass == nil
# organization
assert agent.classified_as == org.classified_as
diff --git a/test/vf/person/domain.test.exs b/test/vf/person/domain.test.exs
@@ -2,7 +2,6 @@ defmodule ZenflowsTest.VF.Person.Domain do
use ZenflowsTest.Help.EctoCase, async: true
alias Ecto.Changeset
-alias Zenflows.Restroom
alias Zenflows.VF.{Person, Person.Domain}
setup ctx do
@@ -13,7 +12,6 @@ setup ctx do
primary_location_id: Factory.insert!(:spatial_thing).id,
user: Factory.uniq("user"),
email: "#{Factory.uniq("user")}@example.com",
- pass_plain: Factory.pass_plain(),
pubkeys_encoded: Base.url_encode64(Jason.encode!(%{a: 1, b: 2, c: 3})),
}
@@ -60,7 +58,6 @@ describe "create/1" do
assert per.primary_location_id == params.primary_location_id
assert per.user == params.user
assert per.email == params.email
- assert Restroom.passverify?(Factory.pass_plain(), per.pass)
assert per.pubkeys == Base.url_decode64!(params.pubkeys_encoded)
end
@@ -79,7 +76,6 @@ describe "update/2" do
assert new.primary_location_id == params.primary_location_id
assert new.user == params.user
assert new.email == old.email
- assert Restroom.passverify?(Factory.pass_plain(), new.pass)
assert new.pubkeys == old.pubkeys
end
@@ -93,7 +89,6 @@ describe "update/2" do
assert new.primary_location_id == old.primary_location_id
assert new.user == old.user
assert new.email == old.email
- assert Restroom.passverify?(Factory.pass_plain(), new.pass)
assert new.pubkeys == old.pubkeys
end
end
diff --git a/test/vf/person/type.test.exs b/test/vf/person/type.test.exs
@@ -10,7 +10,6 @@ setup do
primary_location_id: Factory.insert!(:spatial_thing).id,
user: Factory.uniq("user"),
email: "#{Factory.uniq("user")}@example.com",
- pass_plain: Factory.pass_plain(),
pubkeys_encoded: Base.url_encode64(Jason.encode!(%{a: 1, b: 2, c: 3})),
},
per: Factory.insert!(:person),
@@ -51,7 +50,6 @@ describe "Mutation" do
primaryLocation: "#{params.primary_location_id}"
user: "#{params.user}"
email: "#{params.email}"
- pass: "#{params.pass_plain}"
pubkeys: "#{params.pubkeys_encoded}"
}) {
agent {
@@ -82,7 +80,6 @@ describe "Mutation" do
note: "#{params.note}"
primaryLocation: "#{params.primary_location_id}"
user: "#{params.user}"
- pass: "#{params.pass_plain}"
}) {
agent {
id