|
1 | 1 | RSpec.describe 'PxeServers API' do |
2 | | - let!(:pxe_server) { FactoryBot.create(:pxe_server) } |
| 2 | + let(:pxe_server) { FactoryBot.build(:pxe_server).tap { |x| x.update_authentication(:default => {:userid => 'foo', :password => 'bar'}) } } |
3 | 3 | let!(:pxe_image_1) { FactoryBot.create(:pxe_image, :pxe_server => pxe_server) } |
4 | 4 | let!(:pxe_image_2) { FactoryBot.create(:pxe_image, :pxe_server => pxe_server) } |
5 | 5 | let!(:pxe_menu_1) { FactoryBot.create(:pxe_menu, :pxe_server => pxe_server) } |
|
142 | 142 |
|
143 | 143 | it 'create new pxe server' do |
144 | 144 | api_basic_authorize collection_action_identifier(:pxe_servers, :create, :post) |
145 | | - post(url, :params => {:name => 'foo', :uri => 'bar/quax'}) |
| 145 | + post( |
| 146 | + url, |
| 147 | + :params => { |
| 148 | + :name => 'test server', |
| 149 | + :uri => 'bar://quax', |
| 150 | + :authentication => { |
| 151 | + :userid => 'foo', |
| 152 | + :password => 'bar' |
| 153 | + } |
| 154 | + } |
| 155 | + ) |
| 156 | + expect(response).to have_http_status(:ok) |
| 157 | + expect(response.parsed_body['results'].first['name']).to eq('test server') |
| 158 | + expect(response.parsed_body['results'].first['uri']).to eq('bar://quax') |
| 159 | + expect(response.parsed_body['results'].first['uri_prefix']).to eq('bar') |
| 160 | + end |
| 161 | + |
| 162 | + it 'create new nfs pxe server without authentication' do |
| 163 | + api_basic_authorize collection_action_identifier(:pxe_servers, :create, :post) |
| 164 | + post(url, :params => {:name => 'test server', :uri => 'nfs://quax'}) |
146 | 165 | expect(response).to have_http_status(:ok) |
147 | | - expect(response.parsed_body['results'].first['name']).to eq('foo') |
148 | | - expect(response.parsed_body['results'].first['uri']).to eq('bar/quax') |
| 166 | + expect(response.parsed_body['results'].first['name']).to eq('test server') |
| 167 | + expect(response.parsed_body['results'].first['uri']).to eq('nfs://quax') |
| 168 | + expect(response.parsed_body['results'].first['uri_prefix']).to eq('nfs') |
149 | 169 | end |
150 | 170 |
|
151 | 171 | it 'create new pxe server with pxe menu' do |
152 | 172 | api_basic_authorize collection_action_identifier(:pxe_servers, :create, :post) |
153 | | - post(url, :params => {:name => 'foo', :uri => 'bar/quax', :pxe_menus => [{:file_name => 'menu_1'}]}) |
| 173 | + post(url, :params => {:name => 'foo', :uri => 'bar://quax', |
| 174 | + :pxe_menus => [{:file_name => 'menu_1'}, {:file_name => 'menu_2'}], |
| 175 | + :authentication => {:userid => 'foo', :password => 'bar' }}) |
154 | 176 | expect(response).to have_http_status(:ok) |
155 | 177 | expect(PxeServer.find(response.parsed_body['results'].first['id']).pxe_menus.first[:file_name]).to eq('menu_1') |
156 | 178 | end |
| 179 | + |
| 180 | + it 'fail to create new non nfs pxe server without correct authentication' do |
| 181 | + api_basic_authorize collection_action_identifier(:pxe_servers, :create, :post) |
| 182 | + post(url, :params => {:name => 'test server', :uri => 'smb://quax', :authentication => {:userid => 'user'}}) |
| 183 | + expect(response).to have_http_status(:bad_request) |
| 184 | + end |
| 185 | + |
| 186 | + it 'will forbid create action withouth an appropriate authorization' do |
| 187 | + api_basic_authorize |
| 188 | + post(url, :params => {:name => 'foo', :uri => 'bar/quax', |
| 189 | + :pxe_menus => [{:file_name => 'menu_1'}, {:file_name => 'menu_2'}], |
| 190 | + :authentication => {:userid => 'foo', :password => 'bar' }}) |
| 191 | + expect(response).to have_http_status(:forbidden) |
| 192 | + end |
157 | 193 | end |
158 | 194 |
|
159 | | - describe 'patch /api/pxe_servers/:id' do |
| 195 | + describe 'update /api/pxe_servers/:id' do |
160 | 196 | let(:url) { "/api/pxe_servers/#{pxe_server.id}" } |
161 | 197 |
|
162 | 198 | it 'update pxe server' do |
163 | 199 | api_basic_authorize collection_action_identifier(:pxe_servers, :edit, :patch) |
164 | | - patch(url, :params => {:name => 'updated name', :uri => 'updated/url', :pxe_menus => [{:file_name => 'updated menu'}]}) |
| 200 | + patch(url, :params => {:name => 'updated name', :uri => 'updated://url', :pxe_menus => [{:file_name => 'updated menu'}]}) |
165 | 201 | expect(response).to have_http_status(:ok) |
166 | 202 | expect(response.parsed_body['name']).to eq('updated name') |
167 | | - expect(response.parsed_body['uri']).to eq('updated/url') |
| 203 | + expect(response.parsed_body['uri']).to eq('updated://url') |
168 | 204 | expect(PxeServer.find(response.parsed_body['id']).pxe_menus.first[:file_name]).to eq('updated menu') |
169 | 205 | end |
| 206 | + |
| 207 | + it 'will forbid update action withouth an appropriate authorization' do |
| 208 | + api_basic_authorize |
| 209 | + patch(url, :params => {:name => 'updated name', :uri => 'updated://url', :pxe_menus => [{:file_name => 'updated menu'}]}) |
| 210 | + expect(response).to have_http_status(:forbidden) |
| 211 | + end |
170 | 212 | end |
171 | 213 |
|
172 | 214 | describe 'delete /api/pxe_servers/:id' do |
|
178 | 220 | expect(response).to have_http_status(:no_content) |
179 | 221 | expect(PxeServer.exists?(pxe_server.id)).to be_falsey |
180 | 222 | end |
| 223 | + |
| 224 | + it 'will forbid delete action withouth an appropriate authorization' do |
| 225 | + api_basic_authorize |
| 226 | + delete(url) |
| 227 | + expect(response).to have_http_status(:forbidden) |
| 228 | + end |
181 | 229 | end |
182 | 230 | end |
0 commit comments