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

Patch seems to be broken. #56

Closed
muratseyhan opened this issue Jun 24, 2016 · 3 comments
Closed

Patch seems to be broken. #56

muratseyhan opened this issue Jun 24, 2016 · 3 comments

Comments

@muratseyhan
Copy link
Contributor

patch methods in RDFSource and Container pass a Rack::Lint::InputWrapper object to either LD::Patch.parse or SPARQL.execute depending on the Content-Type. These methods don't support Rack::Lint::InputWrapper, and both fail to execute the valid queries properly.

LD Patch requests have no effect on the resource graph (while they should), and SPARQL Update requests cause the following error.

$ curl -v --request PATCH -d @/home/user/example_patch_sparql.txt http://localhost:9292/ --header "Content-Type:application/sparql-update"
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9292 (#0)
> PATCH / HTTP/1.1
> Host: localhost:9292
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type:application/sparql-update
> Content-Length: 125
> 
* upload completely sent off: 125 out of 125 bytes
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/plain
< Content-Length: 3458
< 
NoMethodError: undefined method `execute' for nil:NilClass
Did you mean?  exec
  ~/.rvm/gems/ruby-2.3.0/gems/sparql-2.0.0/lib/sparql.rb:90:in `execute'
  ~/.rvm/gems/ruby-2.3.0/gems/rdf-ldp-0.6.0/lib/rdf/ldp/rdf_source.rb:202:in `sparql_update'
  ~/thesis/prototype/poc_server/app/rdf_source.rb:8:in `patch'
  ~/thesis/prototype/poc_server/app/resource.rb:23:in `patch'
  ~/.rvm/gems/ruby-2.3.0/gems/rdf-ldp-0.6.0/lib/rdf/ldp/resource.rb:426:in `request'
  ~/.rvm/gems/ruby-2.3.0/gems/rdf-ldp-0.6.0/lib/rack/ldp.rb:108:in `call'
  ~/thesis/prototype/poc_server/app/middleware/header_handler.rb:20:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rdf-ldp-0.6.0/lib/rack/ldp.rb:75:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rdf-ldp-0.6.0/lib/rack/ldp.rb:56:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-linkeddata-1.1.0/lib/rack/linkeddata/conneg.rb:52:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/nulllogger.rb:9:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/sinatra-1.4.7/lib/sinatra/show_exceptions.rb:25:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:182:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:2013:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `block in call'
  ~/.rvm/gems/ruby-2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1787:in `synchronize'
  ~/.rvm/gems/ruby-2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:1487:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/tempfile_reaper.rb:15:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/lint.rb:49:in `_call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/lint.rb:37:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/showexceptions.rb:24:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/commonlogger.rb:33:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/sinatra-1.4.7/lib/sinatra/base.rb:219:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/chunked.rb:54:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/puma-3.4.0/lib/puma/configuration.rb:224:in `call'
  ~/.rvm/gems/ruby-2.3.0/gems/puma-3.4.0/lib/puma/server.rb:569:in `handle_request'
  ~/.rvm/gems/ruby-2.3.0/gems/puma-3.4.0/lib/puma/server.rb:406:in `process_client'
  ~/.rvm/gems/ruby-2.3.0/gems/puma-3.4.0/lib/puma/server.rb:271:in `block in run'
* Connection #0 to host localhost left intact

Where /home/user/example_patch_sparql.txt has the following content:

PREFIX dc: <http://purl.org/dc/elements/1.1/>

INSERT { <http://example/egbook> dc:title  "This is an example title" } WHERE {}

Simply passing env['rack.input'].read instead of env['rack.input'] seems to resolve the issue, since both methods support strings.

@no-reply
Copy link
Member

no-reply commented Jun 26, 2016

On closer inspection, I'm not actually able to repeat this. Using the same SPARQL request as pasted above:

tjohnson@claude:~$ curl -v --request PATCH -d @sparql-patch.txt http:/tent-Type:application/sparql-update"
*   Trying ::1...
* Connected to localhost (::1) port 4567 (#0)
> PATCH / HTTP/1.1
> Host: localhost:4567
> User-Agent: curl/7.48.0
> Accept: */*
> Content-Type:application/sparql-update
> Content-Length: 125
> 
* upload completely sent off: 125 out of 125 bytes
< HTTP/1.1 200 OK 
< Content-Type: text/turtle
< Link: <http://www.w3.org/ns/ldp#Resource>;rel="type",<http://www.w3.org/ns/ldp#RDFSource>;rel="type",<http://www.w3.org/ns/ldp#BasicContainer>;rel="type"
< Allow: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD
< Accept-Post: application/n-triples, text/plain, application/n-quads, text/x-nquads, application/ld+json, application/x-ld+json, application/rdf+json, text/html, application/xhtml+xml, image/svg+xml, text/n3, text/rdf+n3, application/rdf+n3, text/turtle, text/rdf+turtle, application/turtle, application/x-turtle, application/rdf+xml, text/csv, text/tab-separated-values, application/csvm+json, application/trig, application/x-trig, application/trix
< Accept-Patch: text/ldpatch,application/sparql-update
< Etag: W/"2016-06-26T16:27:51.814496814+00:00"
< Last-Modified: Sun, 26 Jun 2016 16:27:51 GMT
< Vary: Accept
< X-Content-Type-Options: nosniff
< Server: WEBrick/1.3.1 (Ruby/2.3.1/2016-04-26)
< Date: Sun, 26 Jun 2016 16:27:51 GMT
< Content-Length: 167
< Connection: Keep-Alive
< 
@prefix dc11: <http://purl.org/dc/elements/1.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example/egbook> dc11:title "This is an example title" .
* Connection #0 to host localhost left intact

Are you able to cook up a failing test?

In the meanwhile, I'm going to work on the Rack::Lint ticket (#58), in hopes that will surface the problem.

no-reply pushed a commit that referenced this issue Jun 26, 2016
The parser methods used to try to handle Strings, as well as valid Rack
inputs. This led to some unnecessary complexity, giving rise to errors
like those seen in #56. This refactors to handle only IO-like Rack Input
streams.

Most of the work here is just to reorganize the tests.

There is an odd case where `RDFSource#update` feeds the IO stream before
trying to parse a graph. For now, we aggressively `#rewind` the stream
in `#parse_graph` to this problem. This might be unduely costly, and
there is probably a better fix in the long run.
@no-reply
Copy link
Member

I think I have this fixed thoroughly in #59. Thanks for the issue report!

I'll get a release with the changes out later today.

@muratseyhan
Copy link
Contributor Author

Thanks for your quick reaction! I will check out the fix. I wonder why we got different behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants