Skip to content

Commit

Permalink
fix parsing issue with empty owner relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Feb 5, 2025
1 parent 06b61cd commit d485239
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gem 'redis', '~> 4.7.1'
gem 'request_migrations', '~> 1.1'

# API params
gem 'typed_params', '~> 1.2.5'
gem 'typed_params', '~> 1.2.6'

# Serializers
gem 'json', '~> 2.3.0'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ GEM
timecop (0.9.5)
timeout (0.4.3)
tracer (0.1.1)
typed_params (1.2.5)
typed_params (1.2.6)
rails (>= 6.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -604,7 +604,7 @@ DEPENDENCIES
temporary_tables
timecop (~> 0.9.5)
tracer
typed_params (~> 1.2.5)
typed_params (~> 1.2.6)
union_of
uri (>= 0.12.2)
verbose_migrations
Expand Down
136 changes: 136 additions & 0 deletions features/api/v1/licenses/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,142 @@ Feature: Create license
And sidekiq should have 0 "metric" jobs
And sidekiq should have 1 "request-log" job

Scenario: Admin creates a license with an empty owner
Given I am an admin of account "test1"
And the current account is "test1"
And the current account has 1 "webhook-endpoint"
And the current account has 1 "policies"
And I use an authentication token
When I send a POST request to "/accounts/test1/licenses" with the following:
"""
{
"data": {
"type": "licenses",
"relationships": {
"owner": {},
"policy": {
"data": {
"type": "policies",
"id": "$policies[0]"
}
}
}
}
}
"""
Then the response status should be "400"
And the first error should have the following properties:
""""
{
"title": "Bad request",
"detail": "is missing",
"source": {
"pointer": "/data/relationships/owner/data"
}
}
"""
And sidekiq should have 0 "webhook" jobs
And sidekiq should have 0 "metric" jobs
And sidekiq should have 1 "request-log" job

Scenario: Admin creates a license with a false owner
Given I am an admin of account "test1"
And the current account is "test1"
And the current account has 1 "webhook-endpoint"
And the current account has 1 "policies"
And I use an authentication token
When I send a POST request to "/accounts/test1/licenses" with the following:
"""
{
"data": {
"type": "licenses",
"relationships": {
"owner": false,
"policy": {
"data": {
"type": "policies",
"id": "$policies[0]"
}
}
}
}
}
"""
Then the response status should be "400"
And the first error should have the following properties:
""""
{
"title": "Bad request",
"detail": "type mismatch (received boolean expected object)",
"source": {
"pointer": "/data/relationships/owner"
}
}
"""
And sidekiq should have 0 "webhook" jobs
And sidekiq should have 0 "metric" jobs
And sidekiq should have 1 "request-log" job

Scenario: Admin creates a license with a null owner (relationship)
Given I am an admin of account "test1"
And the current account is "test1"
And the current account has 1 "webhook-endpoint"
And the current account has 1 "policies"
And I use an authentication token
When I send a POST request to "/accounts/test1/licenses" with the following:
"""
{
"data": {
"type": "licenses",
"relationships": {
"owner": null,
"policy": {
"data": {
"type": "policies",
"id": "$policies[0]"
}
}
}
}
}
"""
Then the response status should be "201"
And the current account should have 1 "license"
And sidekiq should have 1 "webhook" job
And sidekiq should have 1 "metric" job
And sidekiq should have 1 "request-log" job

Scenario: Admin creates a license with a null owner (linkage)
Given I am an admin of account "test1"
And the current account is "test1"
And the current account has 1 "webhook-endpoint"
And the current account has 1 "policies"
And I use an authentication token
When I send a POST request to "/accounts/test1/licenses" with the following:
"""
{
"data": {
"type": "licenses",
"relationships": {
"owner": {
"data": null
},
"policy": {
"data": {
"type": "policies",
"id": "$policies[0]"
}
}
}
}
}
"""
Then the response status should be "201"
And the current account should have 1 "license"
And sidekiq should have 1 "webhook" job
And sidekiq should have 1 "metric" job
And sidekiq should have 1 "request-log" job

Scenario: Admin creates a license for an invalid owner of their account (default)
Given I am an admin of account "test1"
And the current account is "test1"
Expand Down
45 changes: 44 additions & 1 deletion features/api/v1/machines/create.feature
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,50 @@ Feature: Create machine
And sidekiq should have 0 "metric" jobs
And sidekiq should have 1 "request-log" job

Scenario: Admin creates a machine with a nil owner
Scenario: Admin creates a machine with a null owner (relationship)
Given I am an admin of account "test1"
And the current account is "test1"
And the current account has 2 "webhook-endpoints"
And the current account has 1 "user"
And the current account has 1 "license" for the last "user" as "owner"
And I use an authentication token
When I send a POST request to "/accounts/test1/machines" with the following:
"""
{
"data": {
"type": "machines",
"attributes": {
"fingerprint": "4d:Eq:UV:D3:XZ:tL:WN:Bz:mA:Eg:E6:Mk:YX:dK:NC"
},
"relationships": {
"license": {
"data": {
"type": "licenses",
"id": "$licenses[0]"
}
},
"owner": null
}
}
}
"""
Then the response status should be "201"
And the response body should be a "machine" with the fingerprint "4d:Eq:UV:D3:XZ:tL:WN:Bz:mA:Eg:E6:Mk:YX:dK:NC"
And the response body should be a "machine" with the following relationships:
"""
{
"owner": {
"links": { "related": "/v1/accounts/$account/machines/$machines[0]/owner" },
"data": null
}
}
"""
And the response should contain a valid signature header for "test1"
And sidekiq should have 2 "webhook" jobs
And sidekiq should have 1 "metric" job
And sidekiq should have 1 "request-log" job

Scenario: Admin creates a machine with a null owner (linkage)
Given I am an admin of account "test1"
And the current account is "test1"
And the current account has 2 "webhook-endpoints"
Expand Down

0 comments on commit d485239

Please sign in to comment.