user_controller_test.rb 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  1. require 'test_helper'
  2. require 'rake'
  3. class UserControllerTest < ActionDispatch::IntegrationTest
  4. setup do
  5. # set accept header
  6. @headers = { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
  7. # create agent
  8. roles = Role.where(name: %w[Admin Agent])
  9. groups = Group.all
  10. UserInfo.current_user_id = 1
  11. @backup_admin = User.create_or_update(
  12. login: 'backup-admin',
  13. firstname: 'Backup',
  14. lastname: 'Agent',
  15. email: 'backup-admin@example.com',
  16. password: 'adminpw',
  17. active: true,
  18. roles: roles,
  19. groups: groups,
  20. )
  21. @admin = User.create_or_update(
  22. login: 'rest-admin',
  23. firstname: 'Rest',
  24. lastname: 'Agent',
  25. email: 'rest-admin@example.com',
  26. password: 'adminpw',
  27. active: true,
  28. roles: roles,
  29. groups: groups,
  30. )
  31. # create agent
  32. roles = Role.where(name: 'Agent')
  33. @agent = User.create_or_update(
  34. login: 'rest-agent@example.com',
  35. firstname: 'Rest',
  36. lastname: 'Agent',
  37. email: 'rest-agent@example.com',
  38. password: 'agentpw',
  39. active: true,
  40. roles: roles,
  41. groups: groups,
  42. )
  43. # create customer without org
  44. roles = Role.where(name: 'Customer')
  45. @customer_without_org = User.create_or_update(
  46. login: 'rest-customer1@example.com',
  47. firstname: 'Rest',
  48. lastname: 'Customer1',
  49. email: 'rest-customer1@example.com',
  50. password: 'customer1pw',
  51. active: true,
  52. roles: roles,
  53. )
  54. # create orgs
  55. @organization = Organization.create_or_update(
  56. name: 'Rest Org',
  57. )
  58. @organization2 = Organization.create_or_update(
  59. name: 'Rest Org #2',
  60. )
  61. @organization3 = Organization.create_or_update(
  62. name: 'Rest Org #3',
  63. )
  64. # create customer with org
  65. @customer_with_org = User.create_or_update(
  66. login: 'rest-customer2@example.com',
  67. firstname: 'Rest',
  68. lastname: 'Customer2',
  69. email: 'rest-customer2@example.com',
  70. password: 'customer2pw',
  71. active: true,
  72. roles: roles,
  73. organization_id: @organization.id,
  74. )
  75. # configure es
  76. if ENV['ES_URL'].present?
  77. #fail "ERROR: Need ES_URL - hint ES_URL='http://127.0.0.1:9200'"
  78. Setting.set('es_url', ENV['ES_URL'])
  79. # Setting.set('es_url', 'http://127.0.0.1:9200')
  80. # Setting.set('es_index', 'estest.local_zammad')
  81. # Setting.set('es_user', 'elasticsearch')
  82. # Setting.set('es_password', 'zammad')
  83. if ENV['ES_INDEX_RAND'].present?
  84. ENV['ES_INDEX'] = "es_index_#{rand(999_999_999)}"
  85. end
  86. if ENV['ES_INDEX'].blank?
  87. raise "ERROR: Need ES_INDEX - hint ES_INDEX='estest.local_zammad'"
  88. end
  89. Setting.set('es_index', ENV['ES_INDEX'])
  90. travel 1.minute
  91. # drop/create indexes
  92. Rake::Task.clear
  93. Zammad::Application.load_tasks
  94. #Rake::Task["searchindex:drop"].execute
  95. #Rake::Task["searchindex:create"].execute
  96. Rake::Task['searchindex:rebuild'].execute
  97. # execute background jobs
  98. Scheduler.worker(true)
  99. sleep 6
  100. end
  101. UserInfo.current_user_id = nil
  102. end
  103. test 'user create tests - no user' do
  104. post '/api/v1/signshow', params: {}, headers: @headers
  105. # create user with disabled feature
  106. Setting.set('user_create_account', false)
  107. token = @response.headers['CSRF-TOKEN']
  108. # token based on form
  109. params = { email: 'some_new_customer@example.com', authenticity_token: token }
  110. post '/api/v1/users', params: params.to_json, headers: @headers
  111. assert_response(422)
  112. result = JSON.parse(@response.body)
  113. assert(result['error'])
  114. assert_equal('Feature not enabled!', result['error'])
  115. # token based on headers
  116. headers = @headers.merge('X-CSRF-Token' => token)
  117. params = { email: 'some_new_customer@example.com' }
  118. post '/api/v1/users', params: params.to_json, headers: headers
  119. assert_response(422)
  120. result = JSON.parse(@response.body)
  121. assert(result['error'])
  122. assert_equal('Feature not enabled!', result['error'])
  123. Setting.set('user_create_account', true)
  124. # no signup param with enabled feature
  125. params = { email: 'some_new_customer@example.com' }
  126. post '/api/v1/users', params: params.to_json, headers: headers
  127. assert_response(422)
  128. result = JSON.parse(@response.body)
  129. assert(result['error'])
  130. assert_equal('Only signup with not authenticate user possible!', result['error'])
  131. # already existing user with enabled feature
  132. params = { email: 'rest-customer1@example.com', signup: true }
  133. post '/api/v1/users', params: params.to_json, headers: headers
  134. assert_response(422)
  135. result = JSON.parse(@response.body)
  136. assert(result['error'])
  137. assert_equal('Email address is already used for other user.', result['error'])
  138. # email missing with enabled feature
  139. params = { firstname: 'some firstname', signup: true }
  140. post '/api/v1/users', params: params.to_json, headers: headers
  141. assert_response(422)
  142. result = JSON.parse(@response.body)
  143. assert(result['error'])
  144. assert_equal('Attribute \'email\' required!', result['error'])
  145. # email missing with enabled feature
  146. params = { firstname: 'some firstname', signup: true }
  147. post '/api/v1/users', params: params.to_json, headers: headers
  148. assert_response(422)
  149. result = JSON.parse(@response.body)
  150. assert(result['error'])
  151. assert_equal('Attribute \'email\' required!', result['error'])
  152. # create user with enabled feature (take customer role)
  153. params = { firstname: 'Me First', lastname: 'Me Last', email: 'new_here@example.com', signup: true }
  154. post '/api/v1/users', params: params.to_json, headers: headers
  155. assert_response(201)
  156. result = JSON.parse(@response.body)
  157. assert(result)
  158. assert_equal('Me First', result['firstname'])
  159. assert_equal('Me Last', result['lastname'])
  160. assert_equal('new_here@example.com', result['login'])
  161. assert_equal('new_here@example.com', result['email'])
  162. user = User.find(result['id'])
  163. assert_not(user.role?('Admin'))
  164. assert_not(user.role?('Agent'))
  165. assert(user.role?('Customer'))
  166. # create user with admin role (not allowed for signup, take customer role)
  167. role = Role.lookup(name: 'Admin')
  168. params = { firstname: 'Admin First', lastname: 'Admin Last', email: 'new_admin@example.com', role_ids: [ role.id ], signup: true }
  169. post '/api/v1/users', params: params.to_json, headers: headers
  170. assert_response(201)
  171. result = JSON.parse(@response.body)
  172. assert(result)
  173. user = User.find(result['id'])
  174. assert_not(user.role?('Admin'))
  175. assert_not(user.role?('Agent'))
  176. assert(user.role?('Customer'))
  177. # create user with agent role (not allowed for signup, take customer role)
  178. role = Role.lookup(name: 'Agent')
  179. params = { firstname: 'Agent First', lastname: 'Agent Last', email: 'new_agent@example.com', role_ids: [ role.id ], signup: true }
  180. post '/api/v1/users', params: params.to_json, headers: headers
  181. assert_response(201)
  182. result = JSON.parse(@response.body)
  183. assert(result)
  184. user = User.find(result['id'])
  185. assert_not(user.role?('Admin'))
  186. assert_not(user.role?('Agent'))
  187. assert(user.role?('Customer'))
  188. # no user (because of no session)
  189. get '/api/v1/users', params: {}, headers: headers
  190. assert_response(401)
  191. result = JSON.parse(@response.body)
  192. assert_equal('authentication failed', result['error'])
  193. # me
  194. get '/api/v1/users/me', params: {}, headers: headers
  195. assert_response(401)
  196. result = JSON.parse(@response.body)
  197. assert_equal('authentication failed', result['error'])
  198. end
  199. test 'auth tests - not existing user' do
  200. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('not_existing@example.com', 'adminpw')
  201. # me
  202. get '/api/v1/users/me', params: {}, headers: @headers.merge('Authorization' => credentials)
  203. assert_response(401)
  204. result = JSON.parse(@response.body)
  205. assert_equal('authentication failed', result['error'])
  206. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  207. assert_response(401)
  208. result = JSON.parse(@response.body)
  209. assert_equal('authentication failed', result['error'])
  210. end
  211. test 'auth tests - username auth, wrong pw' do
  212. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin', 'not_existing')
  213. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  214. assert_response(401)
  215. result = JSON.parse(@response.body)
  216. assert_equal('authentication failed', result['error'])
  217. end
  218. test 'auth tests - email auth, wrong pw' do
  219. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'not_existing')
  220. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  221. assert_response(401)
  222. result = JSON.parse(@response.body)
  223. assert_equal('authentication failed', result['error'])
  224. end
  225. test 'auth tests - username auth' do
  226. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin', 'adminpw')
  227. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  228. assert_response(200)
  229. result = JSON.parse(@response.body)
  230. assert(result)
  231. end
  232. test 'auth tests - email auth' do
  233. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  234. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  235. assert_response(200)
  236. result = JSON.parse(@response.body)
  237. assert(result)
  238. end
  239. test 'user index and create with admin' do
  240. # email auth
  241. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  242. # me
  243. get '/api/v1/users/me', params: {}, headers: @headers.merge('Authorization' => credentials)
  244. assert_response(200)
  245. result = JSON.parse(@response.body)
  246. assert(result)
  247. assert_equal(result['email'], 'rest-admin@example.com')
  248. # index
  249. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  250. assert_response(200)
  251. result = JSON.parse(@response.body)
  252. assert(result)
  253. # index
  254. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  255. assert_response(200)
  256. result = JSON.parse(@response.body)
  257. assert(result)
  258. assert_equal(result.class, Array)
  259. assert(result.length >= 3)
  260. # show/:id
  261. get "/api/v1/users/#{@agent.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
  262. assert_response(200)
  263. result = JSON.parse(@response.body)
  264. assert(result)
  265. assert_equal(result.class, Hash)
  266. assert_equal(result['email'], 'rest-agent@example.com')
  267. get "/api/v1/users/#{@customer_without_org.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
  268. assert_response(200)
  269. result = JSON.parse(@response.body)
  270. assert(result)
  271. assert_equal(result.class, Hash)
  272. assert_equal(result['email'], 'rest-customer1@example.com')
  273. # create user with admin role
  274. role = Role.lookup(name: 'Admin')
  275. params = { firstname: 'Admin First', lastname: 'Admin Last', email: 'new_admin_by_admin@example.com', role_ids: [ role.id ] }
  276. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  277. assert_response(201)
  278. result = JSON.parse(@response.body)
  279. assert(result)
  280. user = User.find(result['id'])
  281. assert(user.role?('Admin'))
  282. assert_not(user.role?('Agent'))
  283. assert_not(user.role?('Customer'))
  284. assert_equal('new_admin_by_admin@example.com', result['login'])
  285. assert_equal('new_admin_by_admin@example.com', result['email'])
  286. # create user with agent role
  287. role = Role.lookup(name: 'Agent')
  288. params = { firstname: 'Agent First', lastname: 'Agent Last', email: 'new_agent_by_admin1@example.com', role_ids: [ role.id ] }
  289. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  290. assert_response(201)
  291. result = JSON.parse(@response.body)
  292. assert(result)
  293. user = User.find(result['id'])
  294. assert_not(user.role?('Admin'))
  295. assert(user.role?('Agent'))
  296. assert_not(user.role?('Customer'))
  297. assert_equal('new_agent_by_admin1@example.com', result['login'])
  298. assert_equal('new_agent_by_admin1@example.com', result['email'])
  299. role = Role.lookup(name: 'Agent')
  300. params = { firstname: 'Agent First', email: 'new_agent_by_admin2@example.com', role_ids: [ role.id ] }
  301. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  302. assert_response(201)
  303. result = JSON.parse(@response.body)
  304. assert(result)
  305. user = User.find(result['id'])
  306. assert_not(user.role?('Admin'))
  307. assert(user.role?('Agent'))
  308. assert_not(user.role?('Customer'))
  309. assert_equal('new_agent_by_admin2@example.com', result['login'])
  310. assert_equal('new_agent_by_admin2@example.com', result['email'])
  311. assert_equal('Agent', result['firstname'])
  312. assert_equal('First', result['lastname'])
  313. role = Role.lookup(name: 'Agent')
  314. params = { firstname: 'Agent First', email: 'new_agent_by_admin2@example.com', role_ids: [ role.id ] }
  315. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  316. assert_response(422)
  317. result = JSON.parse(@response.body)
  318. assert(result)
  319. assert_equal('Email address is already used for other user.', result['error'])
  320. # missing required attributes
  321. params = { note: 'some note' }
  322. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  323. assert_response(422)
  324. result = JSON.parse(@response.body)
  325. assert(result)
  326. assert_equal('Minimum one identifier (login, firstname, lastname, phone or email) for user is required.', result['error'])
  327. # invalid email
  328. params = { firstname: 'newfirstname123', email: 'some_what', note: 'some note' }
  329. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  330. assert_response(422)
  331. result = JSON.parse(@response.body)
  332. assert(result)
  333. assert_equal('Invalid email', result['error'])
  334. # with valid attributes
  335. params = { firstname: 'newfirstname123', note: 'some note' }
  336. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  337. assert_response(201)
  338. result = JSON.parse(@response.body)
  339. assert(result)
  340. user = User.find(result['id'])
  341. assert_not(user.role?('Admin'))
  342. assert_not(user.role?('Agent'))
  343. assert(user.role?('Customer'))
  344. assert(result['login'].start_with?('auto-'))
  345. assert_equal('', result['email'])
  346. assert_equal('newfirstname123', result['firstname'])
  347. assert_equal('', result['lastname'])
  348. end
  349. test 'user index and create with agent' do
  350. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-agent@example.com', 'agentpw')
  351. # me
  352. get '/api/v1/users/me', params: {}, headers: @headers.merge('Authorization' => credentials)
  353. assert_response(200)
  354. result = JSON.parse(@response.body)
  355. assert(result)
  356. assert_equal(result['email'], 'rest-agent@example.com')
  357. # index
  358. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  359. assert_response(200)
  360. result = JSON.parse(@response.body)
  361. assert(result)
  362. # index
  363. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  364. assert_response(200)
  365. result = JSON.parse(@response.body)
  366. assert(result)
  367. assert_equal(result.class, Array)
  368. assert(result.length >= 3)
  369. get '/api/v1/users?limit=40&page=1&per_page=2', params: {}, headers: @headers.merge('Authorization' => credentials)
  370. assert_response(200)
  371. result = JSON.parse(@response.body)
  372. assert_equal(Array, result.class)
  373. users = User.order(:id).limit(2)
  374. assert_equal(users[0].id, result[0]['id'])
  375. assert_equal(users[1].id, result[1]['id'])
  376. assert_equal(2, result.count)
  377. get '/api/v1/users?limit=40&page=2&per_page=2', params: {}, headers: @headers.merge('Authorization' => credentials)
  378. assert_response(200)
  379. result = JSON.parse(@response.body)
  380. assert_equal(Array, result.class)
  381. users = User.order(:id).limit(4)
  382. assert_equal(users[2].id, result[0]['id'])
  383. assert_equal(users[3].id, result[1]['id'])
  384. assert_equal(2, result.count)
  385. # create user with admin role
  386. firstname = "First test#{rand(999_999_999)}"
  387. role = Role.lookup(name: 'Admin')
  388. params = { firstname: "Admin#{firstname}", lastname: 'Admin Last', email: 'new_admin_by_agent@example.com', role_ids: [ role.id ] }
  389. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  390. assert_response(201)
  391. result_user1 = JSON.parse(@response.body)
  392. assert(result_user1)
  393. user = User.find(result_user1['id'])
  394. assert_not(user.role?('Admin'))
  395. assert_not(user.role?('Agent'))
  396. assert(user.role?('Customer'))
  397. assert_equal('new_admin_by_agent@example.com', result_user1['login'])
  398. assert_equal('new_admin_by_agent@example.com', result_user1['email'])
  399. # create user with agent role
  400. role = Role.lookup(name: 'Agent')
  401. params = { firstname: "Agent#{firstname}", lastname: 'Agent Last', email: 'new_agent_by_agent@example.com', role_ids: [ role.id ] }
  402. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  403. assert_response(201)
  404. result_user1 = JSON.parse(@response.body)
  405. assert(result_user1)
  406. user = User.find(result_user1['id'])
  407. assert_not(user.role?('Admin'))
  408. assert_not(user.role?('Agent'))
  409. assert(user.role?('Customer'))
  410. assert_equal('new_agent_by_agent@example.com', result_user1['login'])
  411. assert_equal('new_agent_by_agent@example.com', result_user1['email'])
  412. # create user with customer role
  413. role = Role.lookup(name: 'Customer')
  414. params = { firstname: "Customer#{firstname}", lastname: 'Customer Last', email: 'new_customer_by_agent@example.com', role_ids: [ role.id ] }
  415. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  416. assert_response(201)
  417. result_user1 = JSON.parse(@response.body)
  418. assert(result_user1)
  419. user = User.find(result_user1['id'])
  420. assert_not(user.role?('Admin'))
  421. assert_not(user.role?('Agent'))
  422. assert(user.role?('Customer'))
  423. assert_equal('new_customer_by_agent@example.com', result_user1['login'])
  424. assert_equal('new_customer_by_agent@example.com', result_user1['email'])
  425. # search as agent
  426. Scheduler.worker(true)
  427. sleep 2 # let es time to come ready
  428. get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}", params: {}, headers: @headers.merge('Authorization' => credentials)
  429. assert_response(200)
  430. result = JSON.parse(@response.body)
  431. assert_equal(Array, result.class)
  432. assert_equal(result_user1['id'], result[0]['id'])
  433. assert_equal("Customer#{firstname}", result[0]['firstname'])
  434. assert_equal('Customer Last', result[0]['lastname'])
  435. assert(result[0]['role_ids'])
  436. assert_not(result[0]['roles'])
  437. get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&expand=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  438. assert_response(200)
  439. result = JSON.parse(@response.body)
  440. assert_equal(Array, result.class)
  441. assert_equal(result_user1['id'], result[0]['id'])
  442. assert_equal("Customer#{firstname}", result[0]['firstname'])
  443. assert_equal('Customer Last', result[0]['lastname'])
  444. assert(result[0]['role_ids'])
  445. assert(result[0]['roles'])
  446. get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  447. assert_response(200)
  448. result = JSON.parse(@response.body)
  449. assert_equal(Array, result.class)
  450. assert_equal(result_user1['id'], result[0]['id'])
  451. assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['label'])
  452. assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['value'])
  453. assert_not(result[0]['role_ids'])
  454. assert_not(result[0]['roles'])
  455. get "/api/v1/users/search?term=#{CGI.escape("Customer#{firstname}")}", params: {}, headers: @headers.merge('Authorization' => credentials)
  456. assert_response(200)
  457. result = JSON.parse(@response.body)
  458. assert_equal(Array, result.class)
  459. assert_equal(result_user1['id'], result[0]['id'])
  460. assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['label'])
  461. assert_equal('new_customer_by_agent@example.com', result[0]['value'])
  462. assert_not(result[0]['role_ids'])
  463. assert_not(result[0]['roles'])
  464. role = Role.find_by(name: 'Agent')
  465. get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&role_ids=#{role.id}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  466. assert_response(200)
  467. result = JSON.parse(@response.body)
  468. assert_equal(Array, result.class)
  469. assert_equal(0, result.count)
  470. role = Role.find_by(name: 'Customer')
  471. get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&role_ids=#{role.id}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  472. assert_response(200)
  473. result = JSON.parse(@response.body)
  474. assert_equal(Array, result.class)
  475. assert_equal(result_user1['id'], result[0]['id'])
  476. assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['label'])
  477. assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['value'])
  478. assert_not(result[0]['role_ids'])
  479. assert_not(result[0]['roles'])
  480. permission = Permission.find_by(name: 'ticket.agent')
  481. get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&permissions=#{permission.name}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  482. assert_response(200)
  483. result = JSON.parse(@response.body)
  484. assert_equal(Array, result.class)
  485. assert_equal(0, result.count)
  486. permission = Permission.find_by(name: 'ticket.customer')
  487. get "/api/v1/users/search?query=#{CGI.escape("Customer#{firstname}")}&permissions=#{permission.name}&label=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  488. assert_response(200)
  489. result = JSON.parse(@response.body)
  490. assert_equal(Array, result.class)
  491. assert_equal(result_user1['id'], result[0]['id'])
  492. assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['label'])
  493. assert_equal("Customer#{firstname} Customer Last <new_customer_by_agent@example.com>", result[0]['value'])
  494. assert_not(result[0]['role_ids'])
  495. assert_not(result[0]['roles'])
  496. end
  497. test 'user index and create with customer1' do
  498. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-customer1@example.com', 'customer1pw')
  499. # me
  500. get '/api/v1/users/me', params: {}, headers: @headers.merge('Authorization' => credentials)
  501. assert_response(200)
  502. result = JSON.parse(@response.body)
  503. assert(result)
  504. assert_equal(result['email'], 'rest-customer1@example.com')
  505. # index
  506. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  507. assert_response(200)
  508. result = JSON.parse(@response.body)
  509. assert_equal(result.class, Array)
  510. assert_equal(result.length, 1)
  511. # show/:id
  512. get "/api/v1/users/#{@customer_without_org.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
  513. assert_response(200)
  514. result = JSON.parse(@response.body)
  515. assert_equal(result.class, Hash)
  516. assert_equal(result['email'], 'rest-customer1@example.com')
  517. get "/api/v1/users/#{@customer_with_org.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
  518. assert_response(401)
  519. result = JSON.parse(@response.body)
  520. assert_equal(result.class, Hash)
  521. assert(result['error'])
  522. # create user with admin role
  523. role = Role.lookup(name: 'Admin')
  524. params = { firstname: 'Admin First', lastname: 'Admin Last', email: 'new_admin_by_customer1@example.com', role_ids: [ role.id ] }
  525. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  526. assert_response(401)
  527. # create user with agent role
  528. role = Role.lookup(name: 'Agent')
  529. params = { firstname: 'Agent First', lastname: 'Agent Last', email: 'new_agent_by_customer1@example.com', role_ids: [ role.id ] }
  530. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  531. assert_response(401)
  532. # search
  533. Scheduler.worker(true)
  534. get "/api/v1/users/search?query=#{CGI.escape('First')}", params: {}, headers: @headers.merge('Authorization' => credentials)
  535. assert_response(401)
  536. end
  537. test 'user index with customer2' do
  538. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-customer2@example.com', 'customer2pw')
  539. # me
  540. get '/api/v1/users/me', params: {}, headers: @headers.merge('Authorization' => credentials)
  541. assert_response(200)
  542. result = JSON.parse(@response.body)
  543. assert(result)
  544. assert_equal(result['email'], 'rest-customer2@example.com')
  545. # index
  546. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  547. assert_response(200)
  548. result = JSON.parse(@response.body)
  549. assert_equal(result.class, Array)
  550. assert_equal(result.length, 1)
  551. # show/:id
  552. get "/api/v1/users/#{@customer_with_org.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
  553. assert_response(200)
  554. result = JSON.parse(@response.body)
  555. assert_equal(result.class, Hash)
  556. assert_equal(result['email'], 'rest-customer2@example.com')
  557. get "/api/v1/users/#{@customer_without_org.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
  558. assert_response(401)
  559. result = JSON.parse(@response.body)
  560. assert_equal(result.class, Hash)
  561. assert(result['error'])
  562. # search
  563. Scheduler.worker(true)
  564. get "/api/v1/users/search?query=#{CGI.escape('First')}", params: {}, headers: @headers.merge('Authorization' => credentials)
  565. assert_response(401)
  566. end
  567. test '04.01 users show and response format' do
  568. roles = Role.where(name: 'Customer')
  569. organization = Organization.first
  570. user = User.create!(
  571. login: 'rest-customer3@example.com',
  572. firstname: 'Rest',
  573. lastname: 'Customer3',
  574. email: 'rest-customer3@example.com',
  575. password: 'customer3pw',
  576. active: true,
  577. organization: organization,
  578. roles: roles,
  579. updated_by_id: @admin.id,
  580. created_by_id: @admin.id,
  581. )
  582. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  583. get "/api/v1/users/#{user.id}", params: {}, headers: @headers.merge('Authorization' => credentials)
  584. assert_response(200)
  585. result = JSON.parse(@response.body)
  586. assert_equal(Hash, result.class)
  587. assert_equal(user.id, result['id'])
  588. assert_equal(user.firstname, result['firstname'])
  589. assert_not(result['organization'])
  590. assert_equal(user.organization_id, result['organization_id'])
  591. assert_not(result['password'])
  592. assert_equal(user.role_ids, result['role_ids'])
  593. assert_equal(@admin.id, result['updated_by_id'])
  594. assert_equal(@admin.id, result['created_by_id'])
  595. get "/api/v1/users/#{user.id}?expand=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  596. assert_response(200)
  597. result = JSON.parse(@response.body)
  598. assert_equal(Hash, result.class)
  599. assert_equal(user.id, result['id'])
  600. assert_equal(user.firstname, result['firstname'])
  601. assert_equal(user.organization_id, result['organization_id'])
  602. assert_equal(user.organization.name, result['organization'])
  603. assert_equal(user.role_ids, result['role_ids'])
  604. assert_not(result['password'])
  605. assert_equal(@admin.id, result['updated_by_id'])
  606. assert_equal(@admin.id, result['created_by_id'])
  607. get "/api/v1/users/#{user.id}?expand=false", params: {}, headers: @headers.merge('Authorization' => credentials)
  608. assert_response(200)
  609. result = JSON.parse(@response.body)
  610. assert_equal(Hash, result.class)
  611. assert_equal(user.id, result['id'])
  612. assert_equal(user.firstname, result['firstname'])
  613. assert_not(result['organization'])
  614. assert_equal(user.organization_id, result['organization_id'])
  615. assert_not(result['password'])
  616. assert_equal(user.role_ids, result['role_ids'])
  617. assert_equal(@admin.id, result['updated_by_id'])
  618. assert_equal(@admin.id, result['created_by_id'])
  619. get "/api/v1/users/#{user.id}?full=true", params: {}, headers: @headers.merge('Authorization' => credentials)
  620. assert_response(200)
  621. result = JSON.parse(@response.body)
  622. assert_equal(Hash, result.class)
  623. assert_equal(user.id, result['id'])
  624. assert(result['assets'])
  625. assert(result['assets']['User'])
  626. assert(result['assets']['User'][user.id.to_s])
  627. assert_equal(user.id, result['assets']['User'][user.id.to_s]['id'])
  628. assert_equal(user.firstname, result['assets']['User'][user.id.to_s]['firstname'])
  629. assert_equal(user.organization_id, result['assets']['User'][user.id.to_s]['organization_id'])
  630. assert_equal(user.role_ids, result['assets']['User'][user.id.to_s]['role_ids'])
  631. get "/api/v1/users/#{user.id}?full=false", params: {}, headers: @headers.merge('Authorization' => credentials)
  632. assert_response(200)
  633. result = JSON.parse(@response.body)
  634. assert_equal(Hash, result.class)
  635. assert_equal(user.id, result['id'])
  636. assert_equal(user.firstname, result['firstname'])
  637. assert_not(result['organization'])
  638. assert_equal(user.organization_id, result['organization_id'])
  639. assert_not(result['password'])
  640. assert_equal(user.role_ids, result['role_ids'])
  641. assert_equal(@admin.id, result['updated_by_id'])
  642. assert_equal(@admin.id, result['created_by_id'])
  643. end
  644. test '04.02 user index and response format' do
  645. roles = Role.where(name: 'Customer')
  646. organization = Organization.first
  647. user = User.create!(
  648. login: 'rest-customer3@example.com',
  649. firstname: 'Rest',
  650. lastname: 'Customer3',
  651. email: 'rest-customer3@example.com',
  652. password: 'customer3pw',
  653. active: true,
  654. organization: organization,
  655. roles: roles,
  656. updated_by_id: @admin.id,
  657. created_by_id: @admin.id,
  658. )
  659. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  660. get '/api/v1/users', params: {}, headers: @headers.merge('Authorization' => credentials)
  661. assert_response(200)
  662. result = JSON.parse(@response.body)
  663. assert_equal(Array, result.class)
  664. assert_equal(Hash, result[0].class)
  665. assert_equal(user.id, result.last['id'])
  666. assert_equal(user.lastname, result.last['lastname'])
  667. assert_not(result.last['organization'])
  668. assert_equal(user.role_ids, result.last['role_ids'])
  669. assert_equal(user.organization_id, result.last['organization_id'])
  670. assert_not(result.last['password'])
  671. assert_equal(@admin.id, result.last['updated_by_id'])
  672. assert_equal(@admin.id, result.last['created_by_id'])
  673. get '/api/v1/users?expand=true', params: {}, headers: @headers.merge('Authorization' => credentials)
  674. assert_response(200)
  675. result = JSON.parse(@response.body)
  676. assert_equal(Array, result.class)
  677. assert_equal(Hash, result[0].class)
  678. assert_equal(user.id, result.last['id'])
  679. assert_equal(user.lastname, result.last['lastname'])
  680. assert_equal(user.organization_id, result.last['organization_id'])
  681. assert_equal(user.organization.name, result.last['organization'])
  682. assert_not(result.last['password'])
  683. assert_equal(@admin.id, result.last['updated_by_id'])
  684. assert_equal(@admin.id, result.last['created_by_id'])
  685. get '/api/v1/users?expand=false', params: {}, headers: @headers.merge('Authorization' => credentials)
  686. assert_response(200)
  687. result = JSON.parse(@response.body)
  688. assert_equal(Array, result.class)
  689. assert_equal(Hash, result[0].class)
  690. assert_equal(user.id, result.last['id'])
  691. assert_equal(user.lastname, result.last['lastname'])
  692. assert_not(result.last['organization'])
  693. assert_equal(user.role_ids, result.last['role_ids'])
  694. assert_equal(user.organization_id, result.last['organization_id'])
  695. assert_not(result.last['password'])
  696. assert_equal(@admin.id, result.last['updated_by_id'])
  697. assert_equal(@admin.id, result.last['created_by_id'])
  698. get '/api/v1/users?full=true', params: {}, headers: @headers.merge('Authorization' => credentials)
  699. assert_response(200)
  700. result = JSON.parse(@response.body)
  701. assert_equal(Hash, result.class)
  702. assert_equal(Array, result['record_ids'].class)
  703. assert_equal(1, result['record_ids'][0])
  704. assert_equal(user.id, result['record_ids'].last)
  705. assert(result['assets'])
  706. assert(result['assets']['User'])
  707. assert(result['assets']['User'][user.id.to_s])
  708. assert_equal(user.id, result['assets']['User'][user.id.to_s]['id'])
  709. assert_equal(user.lastname, result['assets']['User'][user.id.to_s]['lastname'])
  710. assert_equal(user.organization_id, result['assets']['User'][user.id.to_s]['organization_id'])
  711. assert_not(result['assets']['User'][user.id.to_s]['password'])
  712. get '/api/v1/users?full=false', params: {}, headers: @headers.merge('Authorization' => credentials)
  713. assert_response(200)
  714. result = JSON.parse(@response.body)
  715. assert_equal(Array, result.class)
  716. assert_equal(Hash, result[0].class)
  717. assert_equal(user.id, result.last['id'])
  718. assert_equal(user.lastname, result.last['lastname'])
  719. assert_not(result.last['organization'])
  720. assert_equal(user.role_ids, result.last['role_ids'])
  721. assert_equal(user.organization_id, result.last['organization_id'])
  722. assert_not(result.last['password'])
  723. assert_equal(@admin.id, result.last['updated_by_id'])
  724. assert_equal(@admin.id, result.last['created_by_id'])
  725. end
  726. test '04.03 ticket create and response format' do
  727. organization = Organization.first
  728. params = {
  729. firstname: 'newfirstname123',
  730. note: 'some note',
  731. organization: organization.name,
  732. }
  733. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  734. post '/api/v1/users', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  735. assert_response(201)
  736. result = JSON.parse(@response.body)
  737. assert_equal(Hash, result.class)
  738. user = User.find(result['id'])
  739. assert_equal(user.firstname, result['firstname'])
  740. assert_equal(user.organization_id, result['organization_id'])
  741. assert_not(result['organization'])
  742. assert_not(result['password'])
  743. assert_equal(@admin.id, result['updated_by_id'])
  744. assert_equal(@admin.id, result['created_by_id'])
  745. post '/api/v1/users?expand=true', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  746. assert_response(201)
  747. result = JSON.parse(@response.body)
  748. assert_equal(Hash, result.class)
  749. user = User.find(result['id'])
  750. assert_equal(user.firstname, result['firstname'])
  751. assert_equal(user.organization_id, result['organization_id'])
  752. assert_equal(user.organization.name, result['organization'])
  753. assert_not(result['password'])
  754. assert_equal(@admin.id, result['updated_by_id'])
  755. assert_equal(@admin.id, result['created_by_id'])
  756. post '/api/v1/users?full=true', params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  757. assert_response(201)
  758. result = JSON.parse(@response.body)
  759. assert_equal(Hash, result.class)
  760. user = User.find(result['id'])
  761. assert(result['assets'])
  762. assert(result['assets']['User'])
  763. assert(result['assets']['User'][user.id.to_s])
  764. assert_equal(user.id, result['assets']['User'][user.id.to_s]['id'])
  765. assert_equal(user.firstname, result['assets']['User'][user.id.to_s]['firstname'])
  766. assert_equal(user.lastname, result['assets']['User'][user.id.to_s]['lastname'])
  767. assert_not(result['assets']['User'][user.id.to_s]['password'])
  768. assert(result['assets']['User'][@admin.id.to_s])
  769. assert_equal(@admin.id, result['assets']['User'][@admin.id.to_s]['id'])
  770. assert_equal(@admin.firstname, result['assets']['User'][@admin.id.to_s]['firstname'])
  771. assert_equal(@admin.lastname, result['assets']['User'][@admin.id.to_s]['lastname'])
  772. assert_not(result['assets']['User'][@admin.id.to_s]['password'])
  773. end
  774. test '04.04 ticket update and response formats' do
  775. roles = Role.where(name: 'Customer')
  776. organization = Organization.first
  777. user = User.create!(
  778. login: 'rest-customer3@example.com',
  779. firstname: 'Rest',
  780. lastname: 'Customer3',
  781. email: 'rest-customer3@example.com',
  782. password: 'customer3pw',
  783. active: true,
  784. organization: organization,
  785. roles: roles,
  786. updated_by_id: @admin.id,
  787. created_by_id: @admin.id,
  788. )
  789. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  790. params = {
  791. firstname: 'a update firstname #1',
  792. }
  793. put "/api/v1/users/#{user.id}", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  794. assert_response(200)
  795. result = JSON.parse(@response.body)
  796. assert_equal(Hash, result.class)
  797. user = User.find(result['id'])
  798. assert_equal(user.lastname, result['lastname'])
  799. assert_equal(params[:firstname], result['firstname'])
  800. assert_equal(user.organization_id, result['organization_id'])
  801. assert_not(result['organization'])
  802. assert_not(result['password'])
  803. assert_equal(@admin.id, result['updated_by_id'])
  804. assert_equal(@admin.id, result['created_by_id'])
  805. params = {
  806. firstname: 'a update firstname #2',
  807. }
  808. put "/api/v1/users/#{user.id}?expand=true", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  809. assert_response(200)
  810. result = JSON.parse(@response.body)
  811. assert_equal(Hash, result.class)
  812. user = User.find(result['id'])
  813. assert_equal(user.lastname, result['lastname'])
  814. assert_equal(params[:firstname], result['firstname'])
  815. assert_equal(user.organization_id, result['organization_id'])
  816. assert_equal(user.organization.name, result['organization'])
  817. assert_not(result['password'])
  818. assert_equal(@admin.id, result['updated_by_id'])
  819. assert_equal(@admin.id, result['created_by_id'])
  820. params = {
  821. firstname: 'a update firstname #3',
  822. }
  823. put "/api/v1/users/#{user.id}?full=true", params: params.to_json, headers: @headers.merge('Authorization' => credentials)
  824. assert_response(200)
  825. result = JSON.parse(@response.body)
  826. assert_equal(Hash, result.class)
  827. user = User.find(result['id'])
  828. assert(result['assets'])
  829. assert(result['assets']['User'])
  830. assert(result['assets']['User'][user.id.to_s])
  831. assert_equal(user.id, result['assets']['User'][user.id.to_s]['id'])
  832. assert_equal(params[:firstname], result['assets']['User'][user.id.to_s]['firstname'])
  833. assert_equal(user.lastname, result['assets']['User'][user.id.to_s]['lastname'])
  834. assert_not(result['assets']['User'][user.id.to_s]['password'])
  835. assert(result['assets']['User'][@admin.id.to_s])
  836. assert_equal(@admin.id, result['assets']['User'][@admin.id.to_s]['id'])
  837. assert_equal(@admin.firstname, result['assets']['User'][@admin.id.to_s]['firstname'])
  838. assert_equal(@admin.lastname, result['assets']['User'][@admin.id.to_s]['lastname'])
  839. assert_not(result['assets']['User'][@admin.id.to_s]['password'])
  840. end
  841. test '05.01 csv example - customer no access' do
  842. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-customer1@example.com', 'customer1pw')
  843. get '/api/v1/users/import_example', params: {}, headers: @headers.merge('Authorization' => credentials)
  844. assert_response(401)
  845. result = JSON.parse(@response.body)
  846. assert_equal('Not authorized (user)!', result['error'])
  847. end
  848. test '05.02 csv example - admin access' do
  849. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  850. get '/api/v1/users/import_example', params: {}, headers: @headers.merge('Authorization' => credentials)
  851. assert_response(200)
  852. rows = CSV.parse(@response.body)
  853. header = rows.shift
  854. assert_equal('id', header[0])
  855. assert_equal('login', header[1])
  856. assert_equal('firstname', header[2])
  857. assert_equal('lastname', header[3])
  858. assert_equal('email', header[4])
  859. assert(header.include?('organization'))
  860. end
  861. test '05.03 csv import - admin access' do
  862. credentials = ActionController::HttpAuthentication::Basic.encode_credentials('rest-admin@example.com', 'adminpw')
  863. # invalid file
  864. csv_file = ::Rack::Test::UploadedFile.new(Rails.root.join('test', 'fixtures', 'csv', 'user_simple_col_not_existing.csv'), 'text/csv')
  865. post '/api/v1/users/import?try=true', params: { file: csv_file }, headers: { 'Authorization' => credentials }
  866. assert_response(200)
  867. result = JSON.parse(@response.body)
  868. assert_equal(Hash, result.class)
  869. assert_equal('true', result['try'])
  870. assert_equal(2, result['records'].count)
  871. assert_equal('failed', result['result'])
  872. assert_equal(2, result['errors'].count)
  873. assert_equal("Line 1: unknown attribute 'firstname2' for User.", result['errors'][0])
  874. assert_equal("Line 2: unknown attribute 'firstname2' for User.", result['errors'][1])
  875. # valid file try
  876. csv_file = ::Rack::Test::UploadedFile.new(Rails.root.join('test', 'fixtures', 'csv', 'user_simple.csv'), 'text/csv')
  877. post '/api/v1/users/import?try=true', params: { file: csv_file }, headers: { 'Authorization' => credentials }
  878. assert_response(200)
  879. result = JSON.parse(@response.body)
  880. assert_equal(Hash, result.class)
  881. assert_equal('true', result['try'])
  882. assert_equal(2, result['records'].count)
  883. assert_equal('success', result['result'])
  884. assert_nil(User.find_by(login: 'user-simple-import1'))
  885. assert_nil(User.find_by(login: 'user-simple-import2'))
  886. # valid file
  887. csv_file = ::Rack::Test::UploadedFile.new(Rails.root.join('test', 'fixtures', 'csv', 'user_simple.csv'), 'text/csv')
  888. post '/api/v1/users/import', params: { file: csv_file }, headers: { 'Authorization' => credentials }
  889. assert_response(200)
  890. result = JSON.parse(@response.body)
  891. assert_equal(Hash, result.class)
  892. assert_nil(result['try'])
  893. assert_equal(2, result['records'].count)
  894. assert_equal('success', result['result'])
  895. user1 = User.find_by(login: 'user-simple-import1')
  896. assert(user1)
  897. assert_equal(user1.login, 'user-simple-import1')
  898. assert_equal(user1.firstname, 'firstname-simple-import1')
  899. assert_equal(user1.lastname, 'lastname-simple-import1')
  900. assert_equal(user1.email, 'user-simple-import1@example.com')
  901. assert_equal(user1.active, true)
  902. user2 = User.find_by(login: 'user-simple-import2')
  903. assert(user2)
  904. assert_equal(user2.login, 'user-simple-import2')
  905. assert_equal(user2.firstname, 'firstname-simple-import2')
  906. assert_equal(user2.lastname, 'lastname-simple-import2')
  907. assert_equal(user2.email, 'user-simple-import2@example.com')
  908. assert_equal(user2.active, false)
  909. user1.destroy!
  910. user2.destroy!
  911. end
  912. end