An authentication server
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

67 wiersze
2.2 KiB

6 lat temu
6 lat temu
  1. require "./spec_helper"
  2. describe SalesBackend do
  3. it "can render status" do
  4. get "/"
  5. String.from_json(Global.response.not_nil!.body).should eq "OK"
  6. end
  7. it "can add a user able to log in and out" do
  8. Dir.mkdir_p Statics.data_path + "user"
  9. usr = User.new("dummy@domain.com")
  10. usr.password_hash = "mywordismypassword"
  11. post "/user", nil, usr.to_json
  12. Global.response.not_nil!.status_code.should eq(200)
  13. String.from_json(Global.response.not_nil!.body).should eq "OK"
  14. post "/user", nil, usr.to_json
  15. Global.response.not_nil!.status_code.should eq(500)
  16. post "/login", nil, usr.to_json
  17. Global.response.not_nil!.status_code.should eq(200)
  18. uuid = UUID.from_json(Global.response.not_nil!.body).not_nil!
  19. headers = HTTP::Headers.new
  20. headers["user"] = usr.email.to_s
  21. headers["api_token"] = uuid.to_s
  22. get "/user/", headers
  23. Global.response.not_nil!.status_code.should eq(200)
  24. get "/user/address", headers
  25. Global.response.not_nil!.status_code.should eq(200)
  26. Global.response.not_nil!.body.should eq("null")
  27. new_address_str = %([
  28. {
  29. "name": "String",
  30. "address1": "String",
  31. "address2": "{type: String, nilable: true}",
  32. "postcode": "00000",
  33. "city": "String",
  34. "country": 2
  35. }
  36. ])
  37. post "/user/address", headers, new_address_str
  38. Global.response.not_nil!.status_code.should eq(200)
  39. get "/user/address", headers
  40. Global.response.not_nil!.status_code.should eq(200)
  41. address_state = Array(Address).from_json(Global.response.not_nil!.body)
  42. expected_address_state = Array(Address).from_json(new_address_str)
  43. (address_state.to_json==expected_address_state.to_json).should be_true
  44. get "/user/tokens", headers
  45. Global.response.not_nil!.status_code.should eq(200)
  46. usr.tokens = Array(UUID).new
  47. usr.tokens.not_nil!.push uuid
  48. post "/logout", nil, usr.to_json
  49. Global.response.not_nil!.status_code.should eq(200)
  50. get "/user/", headers
  51. Global.response.not_nil!.status_code.should eq(403)
  52. get "/user/address", headers
  53. Global.response.not_nil!.status_code.should eq(403)
  54. get "/user/tokens", headers
  55. Global.response.not_nil!.status_code.should eq(403)
  56. end
  57. end