Skip to content

Commit 494ef1b

Browse files
committed
add code alias to environment tokens
1 parent 3a65417 commit 494ef1b

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

app/controllers/api/v1/environments/relationships/tokens_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def create
8282
def set_environment
8383
scoped_environments = authorized_scope(current_account.environments)
8484

85-
@environment = scoped_environments.find(params[:environment_id])
85+
@environment = FindByAliasService.call(scoped_environments, id: params[:environment_id], aliases: :code)
8686

8787
Current.resource = environment
8888
end

features/api/v1/environments/relationships/tokens.feature

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Feature: Generate authentication token for environment
2222
When I send a GET request to "/accounts/test1/environments/$0/tokens"
2323
Then the response status should be "403"
2424

25-
Scenario: Isolated admin generates a token for an isolated environment
25+
Scenario: Isolated admin generates a token for an isolated environment (by ID)
2626
Given the current account is "test1"
2727
And the current account has 1 isolated "environment"
2828
And the current account has 1 isolated "admin"
@@ -70,6 +70,54 @@ Feature: Generate authentication token for environment
7070
And sidekiq should have 1 "metric" job
7171
And sidekiq should have 1 "request-log" job
7272

73+
Scenario: Isolated admin generates a token for an isolated environment (by code)
74+
Given the current account is "test1"
75+
And the current account has 1 isolated "environment"
76+
And the current account has 1 isolated "admin"
77+
And I am the last admin of account "test1"
78+
And I use an authentication token
79+
And I send the following headers:
80+
"""
81+
{ "Keygen-Environment": "isolated" }
82+
"""
83+
When I send a POST request to "/accounts/test1/environments/isolated/tokens" with the following:
84+
"""
85+
{
86+
"data": {
87+
"type": "tokens",
88+
"attributes": {
89+
"name": "Isolated Token"
90+
}
91+
}
92+
}
93+
"""
94+
Then the response status should be "201"
95+
And the response body should be a "token" with the following relationships:
96+
"""
97+
{
98+
"environment": {
99+
"links": { "related": "/v1/accounts/$account/environments/$environments[0]" },
100+
"data": { "type": "environments", "id": "$environments[0]" }
101+
}
102+
}
103+
"""
104+
And the response body should be a "token" with the following attributes:
105+
"""
106+
{
107+
"name": "Isolated Token",
108+
"kind": "environment-token",
109+
"expiry": null
110+
}
111+
"""
112+
And the response should contain a valid signature header for "test1"
113+
And the response should contain the following headers:
114+
"""
115+
{ "Keygen-Environment": "isolated" }
116+
"""
117+
And sidekiq should have 0 "webhook" jobs
118+
And sidekiq should have 1 "metric" job
119+
And sidekiq should have 1 "request-log" job
120+
73121
Scenario: Shared admin generates a token for an isolated environment
74122
Given the current account is "test1"
75123
And the current account has 1 isolated "environment"

0 commit comments

Comments
 (0)