Giter Site home page Giter Site logo

fernet-ecto's People

Contributors

astjohn avatar jkakar avatar kennyp avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fernet-ecto's Issues

Got error when trying to Fernet.Ecto.String.dump in test

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.