JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources
Disabling JSONAPI.configuration.raise_if_parameters_not_allowed allows you to remove forbidden relationships
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Ruby
- Estrellas
- 2.3k
- Forks
- 546
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
If raise_if_parameters_not_allowed is set to false, then something strange happens.
In https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/request_parser.rb#L237 the params are first filtered using parse_params. Suppose I have a model with an author relationship (like in the tests) that is optional (so presence is not validated) but remove the author from updatable_fields:
class Post < ActiveRecord::Base
belongs_to :author, optional: true
end
class PostResource < JSONAPI::Resource
has_one :author
def self.updatable_fields(context)
super - [:author]
end
end
If I send an update_relationship request to the PostResource, then any relationship data I send to the PostResource gets set to nil. The post's author is set to nil and, since that is a valid value, the update is saved to the database. In other words, the following controller test would fail:
def test_update_relationship_to_one_forbidden_relationship_filtered_parameter
JSONAPI.configuration.raise_if_parameters_not_allowed = false
refute_nil Post.find(1).author
set_content_type_header!
put :update_relationship, params: {post_id: 1, relationship: 'author', data: {anything: "really"}}
assert_response :bad_request
refute_nil Post.find(1).author
ensure
JSONAPI.configuration.raise_if_parameters_not_allowed = true
end
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en lib/jsonapi/request_parser.rb, en la ruta parse_params descrita en el issue, y luego sigue el punto de entrada update_relationship. Usa el escenario de prueba del controlador mencionado para verificar que una relación no permitida no borre el autor existente y que la solicitud devuelva bad_request.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- ruby
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100