Skip to content

[POC] Support to bundle_oauth and bundle_integration_key #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ en:
multiple_channel_integrations: Specifying multiple channel integrations
in requirements.json is not supported.
too_many_oauth_parameters: "Too many parameters with type 'oauth': one permitted"
too_many_bundle_oauth: "Too many parameters with type 'bundle_oauth': one permitted"
too_many_bundle_integration_key: "Too many parameters with type 'bundle_integration_key': one permitted"
missing_bundle_oauth: "Parameter of type 'bundle_integration_key' exist without 'bundle_oauth'"
missing_bundle_integration_key: "Parameter of type 'bundle_oauth' exist without 'bundle_integration_key'"
invalid_use_of_oauth: "Parameter 'oauth' can't exist with 'bundle_integration_key' or 'bundle_oauth'"
invalid_cr_schema_keys:
one: 'Custom resources schema contains an invalid key: %{invalid_keys}'
other: 'Custom resources schema contains invalid keys: %{invalid_keys}'
Expand Down
2 changes: 1 addition & 1 deletion lib/zendesk_apps_support/manifest/parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module ZendeskAppsSupport
class Manifest
class Parameter
TYPES = %w[text password checkbox url number multiline hidden oauth].freeze
TYPES = %w[text password checkbox url number multiline hidden oauth bundle_oauth bundle_integration_key].freeze
ATTRIBUTES = %i[name type required secure default].freeze
attr_reader(*ATTRIBUTES)
def default?
Expand Down
43 changes: 38 additions & 5 deletions lib/zendesk_apps_support/validations/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def collate_manifest_errors(package)
if manifest.marketing_only?
errors.push(*marketing_only_errors(manifest))
else
errors << parameters_error(manifest)
errors << invalid_hidden_parameter_error(manifest)
errors << invalid_type_error(manifest)
errors << too_many_oauth_parameters(manifest)
errors << name_as_parameter_name_error(manifest)
errors.push(*non_marketing_only_errors(manifest))
end

if manifest.requirements_only? || manifest.marketing_only?
Expand All @@ -73,6 +69,43 @@ def marketing_only_errors(manifest)
end
end

def non_marketing_only_errors(manifest)
[].tap do |errors|
errors << parameters_error(manifest)
errors << invalid_hidden_parameter_error(manifest)
errors << invalid_type_error(manifest)
errors << too_many_oauth_parameters(manifest)
errors << name_as_parameter_name_error(manifest)
errors << invalid_use_of_bundle(manifest)
errors << cant_use_oauth_and_bundle(manifest)
end
end

def invalid_use_of_bundle(manifest)
errors = []
bundle_oauth_params = manifest.parameters.select { |x| x.type == 'bundle_oauth' }
bundle_integration_key_params = manifest.parameters.select { |x| x.type == 'bundle_integration_key' }

errors << ValidationError.new(:too_many_bundle_oauth) if bundle_oauth_params.count > 1
errors << ValidationError.new(:too_many_bundle_integration_key) if bundle_integration_key_params.count > 1

if bundle_oauth_params.count != bundle_integration_key_params.count
errors << ValidationError.new(:missing_bundle_oauth) if bundle_oauth_params.count.zero?
errors << ValidationError.new(:missing_bundle_integration_key) if bundle_integration_key_params.count.zero?
end
errors
end

def cant_use_oauth_and_bundle(manifest)
oauth = manifest.parameters.select { |x| x.type == 'oauth' }
bundle_oauth = manifest.parameters.select { |x| x.type == 'bundle_oauth' }
bundle_integration_key = manifest.parameters.select { |x| x.type == 'bundle_integration_key' }

if !oauth.count.zero? && (!bundle_oauth.count.zero? || !bundle_integration_key.count.zero?)
return ValidationError.new(:invalid_use_of_oauth)
end
end

def type_checks(manifest)
errors = []
errors << boolean_error(manifest)
Expand Down
88 changes: 88 additions & 0 deletions spec/validations/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,5 +617,93 @@ def create_package(parameter_hash)
package = create_package(parameter_hash)
expect(package).to have_error "Too many parameters with type 'oauth': one permitted"
end

context 'bundle' do
it 'should have only one bundle_oauth in parameter list' do
parameter_hash = {
'parameters' =>
[
{
'name' => 'bundle_token',
'type' => 'bundle_oauth'
},
{
'name' => 'bundle_token_2',
'type' => 'bundle_oauth'
}
]
}
package = create_package(parameter_hash)
expect(package).to have_error "Too many parameters with type 'bundle_oauth': one permitted"
end

it 'should have only one bundle_integration_key in parameter list' do
parameter_hash = {
'parameters' =>
[
{
'name' => 'bundle_integration_key',
'type' => 'bundle_integration_key'
},
{
'name' => 'bundle_integration_key_2',
'type' => 'bundle_integration_key'
}
]
}
package = create_package(parameter_hash)
expect(package).to have_error "Too many parameters with type 'bundle_integration_key': one permitted"
end

it 'should have a bundle_oauth if a bundle_integration_key exist' do
parameter_hash = {
'parameters' =>
[
{
'name' => 'bundle_integration_key',
'type' => 'bundle_integration_key'
}
]
}
package = create_package(parameter_hash)
expect(package).to have_error "Parameter of type 'bundle_integration_key' exist without 'bundle_oauth'"
end

it 'should have a bundle_oauth if a bundle_oauth exist' do
parameter_hash = {
'parameters' =>
[
{
'name' => 'bundle_token',
'type' => 'bundle_oauth'
}
]
}
package = create_package(parameter_hash)
expect(package).to have_error "Parameter of type 'bundle_oauth' exist without 'bundle_integration_key'"
end
end

it 'should not be exist if oauth exist' do
parameter_hash = {
'parameters' =>
[
{
'name' => 'bundle_token',
'type' => 'bundle_oauth'
},
{
'name' => 'bundle_integration_key',
'type' => 'bundle_integration_key'
},
{
'name' => 'valid parameter',
'type' => 'oauth'
}
]
}
package = create_package(parameter_hash)
expect(package).to have_error "Parameter 'oauth' can't exist with 'bundle_integration_key' or 'bundle_oauth'"
end
end
end