jkakar / fernet-ecto Goto Github PK
View Code? Open in Web Editor NEWFernet.Ecto defines an Ecto.Type that automatically Fernet-encrypts and decrypts text values in a repository.
License: Other
Fernet.Ecto defines an Ecto.Type that automatically Fernet-encrypts and decrypts text values in a repository.
License: Other
Hello.
I'm trying to do this...
defp encrypt_password(changeset) do
case changeset do
%Ecto.Changeset{valid?: true, changes: %{password: password}} ->
put_change(changeset, :password_hash, Fernet.Ecto.String.dump(password))
_ ->
changeset
end
end
... in this test...
test "creates and renders resource when data is valid", %{conn: conn} do
conn = post conn, user_path(conn, :create), user: @valid_attrs
body = json_response(conn, 201)
|> IO.inspect
assert body["data"]["id"]
assert body["data"]["email"]
assert body["data"]["password"]
assert body["data"]["password_hash"]
assert Repo.get_by(User, email: "[email protected]")
end
... and got this:
1) test creates and renders resource when data is valid (Api.UserControllerTest)
test/controllers/user_controller_test.exs:32
** (ArgumentError) argument error
stacktrace:
:erlang.byte_size({:ok, "gAAAAABYzq2ofkNpJauc1vIDNrze1ORAMJXW0j0WN5bDong-cpgYYfaV75RYbX3A5yPl4fo86ctkZfszI8ePXGMejW50eRnfeg=="})
(fernetex) lib/fernetex.ex:193: Fernet.pad/1
(fernetex) lib/fernetex.ex:176: Fernet.encrypt/3
(fernetex) lib/fernetex.ex:154: Fernet.generate/4
(fernet_ecto) lib/fernet_ecto/type.ex:9: Fernet.Ecto.Type.encrypt/2
(ecto) lib/ecto/type.ex:662: Ecto.Type.process_dumpers/3
(ecto) lib/ecto/repo/schema.ex:695: Ecto.Repo.Schema.dump_field!/6
(ecto) lib/ecto/repo/schema.ex:708: anonymous fn/6 in Ecto.Repo.Schema.dump_fields!/5
(stdlib) lists.erl:1263: :lists.foldl/3
(ecto) lib/ecto/repo/schema.ex:706: Ecto.Repo.Schema.dump_fields!/5
(ecto) lib/ecto/repo/schema.ex:655: Ecto.Repo.Schema.dump_changes!/6
(ecto) lib/ecto/repo/schema.ex:200: anonymous fn/13 in Ecto.Repo.Schema.do_insert/4
(api) web/controllers/user_controller.ex:16: Api.UserController.create/2
(api) web/controllers/user_controller.ex:1: Api.UserController.action/2
(api) web/controllers/user_controller.ex:1: Api.UserController.phoenix_controller_pipeline/2
(api) lib/api/endpoint.ex:1: Api.Endpoint.instrument/4
(api) lib/phoenix/router.ex:261: Api.Router.dispatch/2
(api) web/router.ex:1: Api.Router.do_call/2
(api) lib/api/endpoint.ex:1: Api.Endpoint.phoenix_pipeline/1
(api) lib/api/endpoint.ex:1: Api.Endpoint.call/2
When I used the command in iex
, it works ok:
iex(15)> Fernet.Ecto.String.dump("teste")
{:ok,
"gAAAAABYzq-iDjQb5i1MYY8RXbFl9ZFfDQp2wyVWqAdPJIVKgMtFap-P8AtuvsNXqrcedp5CGaJjS9M2kBD60OPOR4l_tkDO8w=="}
iex(16)>
Can you help me to figure out why?
This is the structure in the DB:
schema "users" do
field :name, :string
field :email, :string
field :password, :string, virtual: true
field :password_hash, Fernet.Ecto.String
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.