Skip to content

Commit 89f4472

Browse files
sdelanoSeth Falcon
authored andcommitted
make the default environment immutable
1 parent af8a0f0 commit 89f4472

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

chef-server-api/app/controllers/environments.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def create
6060

6161
# PUT /environments/:id
6262
def update
63+
raise Forbidden if params[:id] == "_default"
6364
begin
6465
env = Chef::Environment.cdb_load(params[:id])
6566
rescue Chef::Exceptions::CouchDBNotFound
@@ -75,6 +76,7 @@ def update
7576

7677
# DELETE /environments/:id
7778
def destroy
79+
raise Forbidden if params[:id] == "_default"
7880
begin
7981
env = Chef::Environment.cdb_load(params[:id])
8082
rescue Chef::Exceptions::CouchDBNotFound

features/api/environments/delete_environment_api.feature

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,13 @@ Feature: Delete environments via the REST API
2626
And an 'environment' named 'cucumber' exists
2727
When I 'DELETE' the path '/environments/cucumber'
2828
Then I should get a '403 "Forbidden"' exception
29+
30+
Scenario Outline: Delete the '_default' environment
31+
Given I am <user_type>
32+
When I 'DELETE' the path '/environments/_default'
33+
Then I should get a '403 "Forbidden"' exception
34+
35+
Examples:
36+
| user_type |
37+
| an administrator |
38+
| a non-admin |

features/api/environments/update_environment_api.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,14 @@ Feature: Update an environment via the REST API
3838
And sending the method 'description' to the 'environment' with 'This will not work'
3939
When I 'PUT' the 'environment' to the path '/environments/cucumber'
4040
Then I should get a '403 "Forbidden"' exception
41+
42+
Scenario Outline: Update the '_default' environment
43+
Given I am <user_type>
44+
And an 'environment' named 'cucumber'
45+
When I 'PUT' the 'environment' to the path '/environments/_default'
46+
Then I should get a '403 "Forbidden"' exception
47+
48+
Examples:
49+
| user_type |
50+
| an administrator |
51+
| a non-admin |

0 commit comments

Comments
 (0)