|
47 | 47 |
|
48 | 48 | expect(response).to have_http_status(:unauthorized)
|
49 | 49 | end
|
| 50 | + |
| 51 | + context "when a user has a readonly token" do |
| 52 | + let(:access) do |
| 53 | + AccessToken.new(owner: :test, permissions: :readonly) |
| 54 | + end |
| 55 | + |
| 56 | + let(:headers) do |
| 57 | + { Authorization: "Token #{token}" } |
| 58 | + end |
| 59 | + |
| 60 | + it "allows access to the API for GET requests" do |
| 61 | + get(forms_path, headers:) |
| 62 | + |
| 63 | + expect(response).to have_http_status(:ok) |
| 64 | + end |
| 65 | + |
| 66 | + it "denies access to the API for POST requests" do |
| 67 | + post(forms_path, params: { form: { name: "test form" } }, headers:) |
| 68 | + |
| 69 | + expect(response).to have_http_status(:unauthorized) |
| 70 | + expect(Form.last).to be nil |
| 71 | + end |
| 72 | + |
| 73 | + it "denies access to the API for PUT requests" do |
| 74 | + form = create :form, id: 1, name: "test form" |
| 75 | + |
| 76 | + put(form_path(1), params: { form: { name: "edited test form" } }, headers:) |
| 77 | + |
| 78 | + expect(response).to have_http_status(:unauthorized) |
| 79 | + expect(form.name).to eq "test form" |
| 80 | + end |
| 81 | + |
| 82 | + it "denies access to the API for PATCH requests" do |
| 83 | + form = create :form, id: 1, name: "test form" |
| 84 | + |
| 85 | + patch(form_path(1), params: { form: { name: "edited test form" } }, headers:) |
| 86 | + |
| 87 | + expect(response).to have_http_status(:unauthorized) |
| 88 | + expect(form.name).to eq "test form" |
| 89 | + end |
| 90 | + |
| 91 | + it "does not allow creating other access tokens" do |
| 92 | + post(access_tokens_path, params: { owner: "test" }, headers:) |
| 93 | + |
| 94 | + expect(response).to have_http_status(:unauthorized) |
| 95 | + end |
| 96 | + end |
50 | 97 | end
|
51 | 98 | end
|
0 commit comments