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

5136 broken thumbnails (alternative solution) #5353

Merged
merged 4 commits into from
Dec 5, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
<session-timeout>
1440
</session-timeout>
<!-- Uncomment the line below to disble `;jsessionid=` in URLs -->
<!-- tracking-mode>COOKIE</tracking-mode -->
</session-config>
<!-- web fonts -->
<mime-mapping>
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
<div id="datasetVersionBlock" class="container-fluid">
<div id="title-block" class="row" jsf:rendered="#{!empty DatasetPage.datasetVersionUI.title.value}">
<div class="col-xs-1 vcenter title-preview-icon-block">
<h:graphicImage value="#{DatasetPage.thumbnailString}" rendered="#{!empty DatasetPage.thumbnailString}"/>
<img src="#{DatasetPage.thumbnailString}" jsf:rendered="#{!empty DatasetPage.thumbnailString}"/>
<span class="icon-dataset" jsf:rendered="#{empty DatasetPage.thumbnailString}"/>
</div>
<div class="col-xs-11 vcenter">
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/filesFragment.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<span class="file-thumbnail-preview-img" jsf:rendered="#{!empty fileMetadata.dataFile.id and DatasetPage.isThumbnailAvailable(fileMetadata)}"
data-container="body" data-toggle="popover" data-placement="top" data-trigger="hover" data-html="true" data-content="&lt;img src=&#34;/api/access/datafile/#{fileMetadata.dataFile.id}?imageThumb=400&#34; alt=&#34; #{bundle['file.preview']} #{fileMetadata.label}&#34; /&gt;">

<h:graphicImage value="#{DatasetPage.getDataFileThumbnailAsBase64(fileMetadata)}" />
<img src="#{DatasetPage.getDataFileThumbnailAsBase64(fileMetadata)}" />
</span>

<!-- Default Icon -->
Expand Down
72 changes: 72 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/DatasetsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -761,13 +761,85 @@ public void testPrivateUrl() {
* asadmin create-jvm-options
* "-Ddataverse.siteUrl=http\://localhost\:8080"
*/

/*
* Attempt to follow the private link url; as a user not otherwise
* authorized to view the draft - and make sure they get the dataset page:
*
* MAKE SURE TO READ the note below, about jsessions and cookies!
*/

Response getDatasetAsUserWhoClicksPrivateUrl = given()
.header(API_TOKEN_HTTP_HEADER, apiToken)
.get(urlWithToken);
String title = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.head.title");
assertEquals("Darwin's Finches - " + dataverseAlias, title);
assertEquals(OK.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode());

/*
* NOTE, this is what happens when we attempt to access the dataset via the
* private url, as implemented above:
*
* The private url page authorizes the user to view the dataset
* by issuing a new jsession, and issuing a 302 redirect to the dataset
* page WITH THE JSESSIONID ADDED TO THE URL - as in
* dataset.xhtml?persistentId=xxx&jsessionid=yyy
* RestAssured's .get() method follows redirects by default - so in the
* end the above works and we get the correct dataset.
* But note that this relies on the jsessionid in the url. We've
* experimented with disabling url-supplied jsessions (in PR #5316);
* then the above stopped working - because now jsession is supplied
* AS A COOKIE, which the RestAssured code above does not use, so
* the dataset page refuses to show the dataset to the user. (So the
* assertEquals code above fails, because the page title is not "Darwin's Finches",
* but "Login Page")
* Below is an implementation of the test above that uses the jsession
* cookie, instead of relying on the jsessionid in the URL:

// This should redirect us to the actual dataset page, and
// give us a valid session cookie:

Response getDatasetAsUserWhoClicksPrivateUrl = given()
.header(API_TOKEN_HTTP_HEADER, apiToken)
.redirects().follow(false)
.get(urlWithToken);
// (note that we have purposefully asked not to follow redirects
// automatically; this way we can test that we are being redirected
// to the right place, that we've been given the session cookie, etc.

assertEquals(FOUND.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode());
// Yes, javax.ws.rs.core.Response.Status.FOUND is 302!
String title = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.head.title");
assertEquals("Document moved", title);

String redirectLink = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.body.a.@href");
assertNotNull(redirectLink);
assertTrue(redirectLink.contains("dataset.xhtml"));

String jsessionid = getDatasetAsUserWhoClicksPrivateUrl.cookie("jsessionid");
assertNotNull(jsessionid);

// ... and now we can try and access the dataset, with another HTTP GET,
// sending the jsession cookie along:

try {
redirectLink = URLDecoder.decode(redirectLink, "UTF-8");
} catch (UnsupportedEncodingException ex) {
// do nothing - try to redirect to the url as is?
}

logger.info("redirecting to "+redirectLink+", using jsession "+jsessionid);

getDatasetAsUserWhoClicksPrivateUrl = given()
.cookies("JSESSIONID", jsessionid)
.get(redirectLink);

assertEquals(OK.getStatusCode(), getDatasetAsUserWhoClicksPrivateUrl.getStatusCode());
title = getDatasetAsUserWhoClicksPrivateUrl.getBody().htmlPath().getString("html.head.title");
assertEquals("Darwin's Finches - " + dataverseAlias, title);

*/

Response junkPrivateUrlToken = given()
.header(API_TOKEN_HTTP_HEADER, apiToken)
.get("/privateurl.xhtml?token=" + "junk");
Expand Down