Browse Source

Allow json import to have passwords and hash these.

feature/tags
Bèr Kessels 11 months ago
parent
commit
690a205b2a
3 changed files with 17 additions and 1 deletions
  1. 7
    0
      bin/sink
  2. 3
    1
      test/fixtures/input/harry_potter.json
  3. 7
    0
      test/integration/cli/sink_test.rb

+ 7
- 0
bin/sink View File

@@ -4,6 +4,7 @@
$LOAD_PATH << '.'

require 'bundler/setup'
require 'bcrypt'
require 'logger'
require 'securerandom'
require 'yajl'
@@ -21,6 +22,8 @@ LOG_LEVEL = ENV['LOG_LEVEL'].to_i || Logger::DEBUG
# Handles a stream of nodes in STDIN emits them as events through the
# AddMemberCommand.
class EventSink
include BCrypt

def initialize
@parser = Yajl::Parser.new(symbolize_keys: true)
@parser.on_parse_complete = method(:object_parsed)
@@ -31,7 +34,11 @@ class EventSink

def object_parsed(obj)
log(Logger::DEBUG, '-- parsed object')

obj[:aggregate_id] ||= SecureRandom.uuid

obj[:password] = Password.create(obj[:password]) if obj.key?(:password)

command = Commands::Member::AddMember::Command.new(obj)
Commands::Member::AddMember::CommandHandler.new(command: command).handle
rescue BadRequest => e

+ 3
- 1
test/fixtures/input/harry_potter.json View File

@@ -1,5 +1,7 @@
{
"bio": "Fought a snakey guy, now proud father and civil servant",
"name": "Harry Potter",
"email": "hpotter@example.org"
"email": "hpotter@example.org",
"username": "hpotter",
"password": "caput draconis"
}

+ 7
- 0
test/integration/cli/sink_test.rb View File

@@ -1,6 +1,8 @@
# frozen_string_literal: true

require 'test_helper'

require 'bcrypt'
require 'open3'

##
@@ -18,6 +20,11 @@ class SinkTest < Minitest::Spec
assert_equal(last_event.body['name'], 'Harry Potter')
end

it 'hashes password' do
run_sink_pipe
assert(BCrypt::Password.new(last_event.body['password']), 'caput draconis')
end

it 'updates duplicates and continues' do
run_sink_pipe
run_sink_pipe

Loading…
Cancel
Save