Skip to content

Commit 7379d6b

Browse files
authored
Merge pull request #372 from zendesk/mtsolakis/APPS-7218-add-warning-for-password-parameter
[APPS-7218] Add warning for password parameter
2 parents a69fa12 + 50a2855 commit 7379d6b

File tree

5 files changed

+34
-21
lines changed

5 files changed

+34
-21
lines changed

config/locales/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ en:
123123
for %{product}: %{missing_key}'
124124
products_do_not_match_manifest_products: Products in manifest (%{manifest_products})
125125
do not match products in translations (%{translation_products})
126+
password_parameter_deprecated: 'Password parameter type is deprecated and will not
127+
be accepted in the future. Use Basic Access Authentication instead. Learn more: %{link}.'
126128
insecure_token_parameter_in_manifest: 'Make sure to set secure to true
127129
when using keys in Settings. Learn more: %{link}'
128130
default_secure_or_hidden_parameter_in_manifest: Default values for secure

lib/zendesk_apps_support/package.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def initialize(dir, is_cached = true)
3131
@warnings = []
3232
end
3333

34-
def validate(marketplace: true, skip_marketplace_translations: false, apply_password_parameter_check: false)
34+
def validate(marketplace: true, skip_marketplace_translations: false, error_on_password_parameter: false)
3535
errors = []
36-
errors << Validations::Manifest.call(self, apply_password_parameter_check: apply_password_parameter_check)
36+
errors << Validations::Manifest.call(self, error_on_password_parameter: error_on_password_parameter)
3737

3838
if has_valid_manifest?(errors)
3939
errors << Validations::Marketplace.call(self) if marketplace
@@ -61,8 +61,8 @@ def validate(marketplace: true, skip_marketplace_translations: false, apply_pass
6161
errors.flatten.compact
6262
end
6363

64-
def validate!(marketplace: true, skip_marketplace_translations: false, apply_password_parameter_check: false)
65-
errors = validate(marketplace: marketplace, skip_marketplace_translations: skip_marketplace_translations, apply_password_parameter_check: apply_password_parameter_check)
64+
def validate!(marketplace: true, skip_marketplace_translations: false, error_on_password_parameter: false)
65+
errors = validate(marketplace: marketplace, skip_marketplace_translations: skip_marketplace_translations, error_on_password_parameter: error_on_password_parameter)
6666
raise errors.first if errors.any?
6767
true
6868
end

lib/zendesk_apps_support/validations/manifest.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Manifest
1313
OAUTH_MANIFEST_LINK = 'https://developer.zendesk.com/apps/docs/developer-guide/manifest#oauth'
1414

1515
class << self
16-
def call(package, apply_password_parameter_check: false)
16+
def call(package, error_on_password_parameter: false)
1717
unless package.has_file?('manifest.json')
1818
nested_manifest = package.files.find { |file| file =~ %r{\A[^/]+?/manifest\.json\Z} }
1919
if nested_manifest
@@ -22,7 +22,9 @@ def call(package, apply_password_parameter_check: false)
2222
return [ValidationError.new(:missing_manifest)]
2323
end
2424

25-
collate_manifest_errors(package, apply_password_parameter_check)
25+
package.warnings << password_parameter_warning unless error_on_password_parameter
26+
27+
collate_manifest_errors(package, error_on_password_parameter)
2628
rescue JSON::ParserError => e
2729
return [ValidationError.new(:manifest_not_json, errors: e)]
2830
rescue ZendeskAppsSupport::Manifest::OverrideError => e
@@ -31,7 +33,7 @@ def call(package, apply_password_parameter_check: false)
3133

3234
private
3335

34-
def collate_manifest_errors(package, apply_password_parameter_check)
36+
def collate_manifest_errors(package, error_on_password_parameter)
3537
manifest = package.manifest
3638

3739
errors = [
@@ -50,7 +52,7 @@ def collate_manifest_errors(package, apply_password_parameter_check)
5052
invalid_version_error(manifest) ]
5153
end,
5254
ban_no_template(manifest),
53-
if apply_password_parameter_check
55+
if error_on_password_parameter
5456
[ deprecate_password_parameter_type(manifest) ]
5557
end
5658
]
@@ -449,6 +451,13 @@ def valid_url?(value)
449451
rescue URI::InvalidURIError
450452
false
451453
end
454+
455+
def password_parameter_warning
456+
I18n.t(
457+
'txt.apps.admin.error.app_build.translation.password_parameter_deprecated',
458+
link: 'https://developer.zendesk.com/documentation/apps/app-developer-guide/making-api-requests-from-a-zendesk-app/#using-basic-access-authentication'
459+
)
460+
end
452461
end
453462
end
454463
end

spec/package_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,15 @@ def build_app_source_with_files(files)
455455
end
456456
end
457457

458-
context 'when apply_password_parameter_check is true' do
458+
context 'when error_on_password_parameter is true' do
459459
let(:package) { ZendeskAppsSupport::Package.new('spec/fixtures/iframe_only_app') }
460460

461461
before do
462462
allow(ZendeskAppsSupport::Validations::Manifest).to receive(:call)
463-
package.validate!(marketplace: true, apply_password_parameter_check: true)
463+
package.validate!(marketplace: true, error_on_password_parameter: true)
464464
end
465-
it 'validate manifest and passes in the apply_password_parameter_check correctly' do
466-
expect(ZendeskAppsSupport::Validations::Manifest).to have_received(:call).with(package, {:apply_password_parameter_check => true})
465+
it 'validate manifest and passes in the error_on_password_parameter correctly' do
466+
expect(ZendeskAppsSupport::Validations::Manifest).to have_received(:call).with(package, {:error_on_password_parameter => true})
467467
end
468468
end
469469
end

spec/validations/manifest_spec.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -814,35 +814,37 @@ def create_package(parameter_hash)
814814
end
815815
end
816816

817-
context 'when the apply_password_parameter_check option is set to false' do
817+
context 'when the error_on_password_parameter option is set to false' do
818818

819-
it 'should be valid with a password param type' do
820-
apply_password_parameter_check = false
819+
it 'should be valid but add a warning about the password param type' do
820+
error_on_password_parameter = false
821821
@manifest_hash = {
822822
'parameters' => [
823823
'name' => 'a password param',
824824
'type' => 'password',
825825
]}
826826
package = create_package(@manifest_hash)
827-
errors = ZendeskAppsSupport::Validations::Manifest.call(package, apply_password_parameter_check: apply_password_parameter_check)
827+
errors = ZendeskAppsSupport::Validations::Manifest.call(package, error_on_password_parameter: error_on_password_parameter)
828828

829829
expect(errors.map(&:to_s).join()).not_to include("Password parameter type can no longer be used")
830+
expect(package.warnings.join()).to include("Password parameter type is deprecated and will not be accepted in the future")
830831
end
831832
end
832833

833-
context 'when the apply_password_parameter_check option is set to true' do
834+
context 'when the error_on_password_parameter option is set to true' do
834835

835-
it 'should not be valid with a password param type' do
836-
apply_password_parameter_check = true
836+
it 'should not be valid with a password param type and add no warnings' do
837+
error_on_password_parameter = true
837838
@manifest_hash = {
838839
'parameters' => [
839840
'name' => 'a password param',
840841
'type' => 'password',
841842
]}
842843
package = create_package(@manifest_hash)
843-
errors = ZendeskAppsSupport::Validations::Manifest.call(package, apply_password_parameter_check: apply_password_parameter_check)
844-
844+
errors = ZendeskAppsSupport::Validations::Manifest.call(package, error_on_password_parameter: error_on_password_parameter)
845+
845846
expect(errors.map(&:to_s).join()).to include("Password parameter type can no longer be used")
847+
expect(package.warnings.join()).not_to include("Password parameter type is deprecated and will not be accepted in the future")
846848
end
847849
end
848850
end

0 commit comments

Comments
 (0)