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

Headers passthru #64

Merged
merged 3 commits into from
Apr 12, 2017
Merged

Headers passthru #64

merged 3 commits into from
Apr 12, 2017

Conversation

dannylamb
Copy link
Contributor

GitHub Issue: part of Islandora/documentation#597

What does this Pull Request do?

Adds parameters to functions in IFedoraApi and its implementations so that we can pass authorization tokens through to Fedora. I ran into this when trying to issue a HEAD request to get an ETag.

What's new?

The interface changes above. I also ran into a funky issue with how Guzzle clients handle their base uri, so I added some sanitization around that so no one else wastes an hour next time they don't add the trailing slash to their fedora base url.

How should this be tested?

Before this PR, give Chullo a base url of http://localhost:8080/fcrepo/rest and issue a PUT request to http://localhost:8080/fcrepo/rest/foo. You should get denied with a 403.

Pull in this PR and do the same. You should get a successful response and be able to visit the created resource.

You can then also issue HEAD, OPTION, and DELETE requests passing in your JWT as the 'Authorization' header with a FedoraApi class. Analogous functions in Chullo have also been updated, so you can try those out too.

Interested parties

@Islandora-CLAW/committers

@codecov
Copy link

codecov bot commented Apr 12, 2017

Codecov Report

Merging #64 into master will increase coverage by 0.17%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #64      +/-   ##
==========================================
+ Coverage   93.45%   93.63%   +0.17%     
==========================================
  Files           3        3              
  Lines         107      110       +3     
==========================================
+ Hits          100      103       +3     
  Misses          7        7
Impacted Files Coverage Δ
src/Chullo.php 91.52% <100%> (+0.45%) ⬆️
src/FedoraApi.php 95.45% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac54f79...96981ae. Read the comment docs.

@ruebot
Copy link
Member

ruebot commented Apr 12, 2017

Tested and works!

<?php

require __DIR__ . '/chullo/vendor/autoload.php';

use Islandora\Chullo\FedoraApi;

$chullo = FedoraApi::create("http://localhost:8080/fcrepo/rest");

try {
  $uri = $chullo->saveResource("not_the_full_uri", "", ['Authorization' => "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE0OTIwMjIwNDAsImV4cCI6MTQ5MjAyOTI0MCwidWlkIjoiMSIsIm5hbWUiOiJhZG1pbiIsInJvbGVzIjpbImF1dGhlbnRpY2F0ZWQiLCJhZG1pbmlzdHJhdG9yIl0sInVybCI6Imh0dHBzOlwvXC9sb2NhbGhvc3Q6ODAwMCJ9.aCZ-CkdUlNyBmXjU9snP2gGuzYCaFO694sJQ81UE-tSslyS8TuEakD58JEpOY58b2aM-JkX3E8wYJXeVNY2WN8BAOkHnqrYzUe324jYy9wjiiCj5nsB_YJeh7Un0nSRom-FbZ42sQQekVoUu4nxVxisj00mSWbSDxusN-0dt0jazUjBkncdhj3hoABUZ14hCFJzdYmUVyoDoqybLJM1kxiH4OD1iBpZV8NXeCI3XfXi8HowZdZO1CMoMDLEQB9aRVpG5E1ntmc-FChb5rsNRomJ3d71iascq8JKFFC4M_WByPKt5705l4S5i-RFqnbuXFfLaFV5N3DwfRDaEDk60Vg"]);
  echo $uri->getStatusCode();
  echo "\n";
  echo $uri->getBody();
  echo "\n";
} catch (Exception $e) {
  echo 'Caught exception: ',  $e->getMessage(), "\n";
}

?>

Without PR applied:

$ php test_pr.php 
403
<!DOCTYPE html><html><head><title>Apache Tomcat/8.0.32 (Ubuntu) - Error report</title><style type="text/css">H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}.line {height: 1px; background-color: #525D76; border: none;}</style> </head><body><h1>HTTP Status 403 - </h1><div class="line"></div><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Access to the specified resource has been forbidden.</u></p><hr class="line"><h3>Apache Tomcat/8.0.32 (Ubuntu)</h3></body></html>

With PR applied:

$ php test_pr.php 
201
http://localhost:8080/fcrepo/rest/not_the_full_uri

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

Successfully merging this pull request may close these issues.

2 participants