Skip to content
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

Remove the yml extension from field_apidoc_file_link and field_apidoc_spec allowed values - 3.x branch #176

Merged
merged 4 commits into from
Mar 30, 2022
Merged
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
7 changes: 7 additions & 0 deletions apigee_api_catalog.install
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,10 @@ function apigee_api_catalog_update_8808() {
function apigee_api_catalog_update_8809() {
return \Drupal::service('apigee_api_catalog.updates')->update8809();
}

/**
* Removed yml extension from field_apidoc_file_link and field_apidoc_spec allowed values.
*/
function apigee_api_catalog_update_8810() {
return \Drupal::service('apigee_api_catalog.updates')->update8810();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ default_value_callback: ''
settings:
link_type: 17
title: 0
file_extensions: 'yml yaml json'
file_extensions: 'yaml json'
no_extension: false
field_type: file_link
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ default_value: { }
default_value_callback: ''
settings:
file_directory: apidoc_specs
file_extensions: 'yml yaml json'
file_extensions: 'yaml json'
max_filesize: ''
description_field: false
handler: 'default:file'
Expand Down
4 changes: 2 additions & 2 deletions src/Entity/ApiDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setRevisionable(TRUE)
->setSettings([
'file_directory' => 'apidoc_specs',
'file_extensions' => 'yml yaml json',
'file_extensions' => 'yaml json',
'handler' => 'default:file',
'text_processing' => 0,
])
Expand All @@ -279,7 +279,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setDescription(t('The URL to an OpenAPI file spec.'))
->addConstraint('ApiDocFileLink')
->setSettings([
'file_extensions' => 'yml yaml json',
'file_extensions' => 'yaml json',
'link_type' => LinkItemInterface::LINK_GENERIC,
'title' => DRUPAL_DISABLED,
])
Expand Down
23 changes: 23 additions & 0 deletions src/UpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,29 @@ public function update8809() {
->save();
}

/**
* Removed .yml file upload for security reasons.
*/
public function update8810() {
$fields = [
'field_apidoc_file_link',
'field_apidoc_spec',
];

foreach ($fields as $field) {
$fieldConfig = FieldConfig::loadByName('node', 'apidoc', $field);
// Only look for yml extension.
$extensions = $fieldConfig->getSetting('file_extensions');
if (strpos($extensions, 'yml') !== FALSE) {
// Remove yml extension from allowed values.
$fieldConfig->setSetting('file_extensions', 'yaml json')
->save();
}
}

return 'Removed the yml extension from field_apidoc_file_link and field_apidoc_spec allowed values for security reasons.';
}

/**
* Get the field map from apidoc fields to node fields.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Functional/ApiDocsAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public function testApiDocAdministration() {
// Create a new spec in site.
$file = File::create([
'uid' => $this->adminUser->id(),
'filename' => 'specA.yml',
'uri' => 'public://specA.yml',
'filename' => 'specA.yaml',
'uri' => 'public://specA.yaml',
'filemime' => 'application/octet-stream',
'created' => 1,
'changed' => 1,
Expand Down Expand Up @@ -146,7 +146,7 @@ public function testApiDocAdministration() {
// Edit form should have proper values.
$assert->fieldValueEquals('title[0][value]', $random_name);
$assert->fieldValueEquals('body[0][value]', $random_description);
$assert->linkExists('specA.yml');
$assert->linkExists('specA.yaml');

// Delete the entity.
$this->clickLink('Delete');
Expand Down