Skip to content

Commit

Permalink
Merge pull request #145 from SolidLabResearch/fix/sources-from-indexF…
Browse files Browse the repository at this point in the history
…ile-problem

Fix/sources from index file problem
  • Loading branch information
EmilioTR authored Jun 27, 2024
2 parents fb444e0 + 5db57b1 commit 5870c72
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Forced CSS's to not return content type application/ld+json, which induced a CORS error on some CSS server versions (#131).
- Queries based on index file now work for any variable, not just ?object (#136).
- Queries based on index file now work for index files requiring authentication (#139).

## [1.2.1] - 2024-06-17

Expand Down
53 changes: 50 additions & 3 deletions cypress/e2e/sources-from-indexfile.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("Sources from index file", () => {

// Check that it indeed had 3 sources
cy.get('.information-box').contains('Sources: 3');

// Check if correct data is displayed
cy.contains("http://www/example.com/data/component-c01");
cy.contains("Component 1");
Expand All @@ -31,7 +31,7 @@ describe("Sources from index file", () => {

// Check that all 4 sources were used
cy.get('.information-box').contains('Sources: 4');

// Check if correct data is still displayed even if one source was unauthorized
cy.contains("http://www/example.com/data/component-c01");
cy.contains("Component 1");
Expand All @@ -50,11 +50,58 @@ describe("Sources from index file", () => {

// Check that the 4 sources were successfully merged
cy.get('.information-box').contains('Sources: 4');

// Check if correct data is still displayed even if one source was unauthorized and different sources were merged
cy.contains("http://www/example.com/data/component-c01");
cy.contains("Component 1");
cy.contains("Material 1");
});

it("Sources from an unauthorized source. Before and after log in.", () => {
cy.visit("/");

cy.intercept('GET', 'http://localhost:8080/example/index-example-texon-only-AUTH').as('getRequest');

// Navigate to correct query
cy.contains("For testing only").click();
cy.contains("Sources from an index file (requiring authentication)").click();

// Wait for the request and assert the response
cy.wait('@getRequest').then((interception) => {
expect(interception.response.statusCode).to.equal(401);
});


cy.contains("http://www/example.com/data/component-c01").should("not.exist");
cy.contains("Component 1").should("not.exist");
cy.contains("Material 1").should("not.exist");

//log in
cy.get('[aria-label="Profile"]').click();
cy.contains('[role="menuitem"]', "Login").click();

cy.get('input[name="idp"]')
.clear();
cy.get('input[name="idp"]')
.type("http://localhost:8080/example/profile/card#me");
cy.contains("Login").click();

cy.get("input#email").type("[email protected]");
cy.get("input#password").type("abc123");
cy.contains("button", "Log in").click();
cy.contains("button", "Authorize").click();

cy.url().should("eq", "http://localhost:5173/");

//now try again
cy.contains("For testing only").click();
cy.contains("Sources from an index file (requiring authentication)").click();

cy.contains("http://www/example.com/data/component-c01").should("not.exist");
cy.contains("Component 1").should("exist");
cy.contains("Material 1").should("exist");
})



});
7 changes: 7 additions & 0 deletions initial-pod-data/index-example-texon-only-AUTH$.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<#index-example> rdfs:seeAlso
<http://localhost:8080/example/boms>,
<http://localhost:8080/example/components>,
<http://localhost:8080/example/materials>
.
9 changes: 9 additions & 0 deletions initial-pod-data/index-example-texon-only-AUTH.acl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
@prefix foaf: <http://xmlns.com/foaf/0.1/>.

<#owner>
a acl:Authorization;
acl:accessTo <./index-example-texon-only-AUTH>;
acl:agent <http://localhost:8080/example/profile/card#me>;
acl:mode acl:Read, acl:Write, acl:Control.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX example: <http://localhost:8080/example/index-example-texon-only-AUTH#>

SELECT ?object
WHERE {
example:index-example rdfs:seeAlso ?object .
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const LogoutButton = forwardRef((props, ref) => {
function handleLogout(event) {
event.preventDefault();
if (isLoggedIn) {
redirect("/");
logout();
} else {
redirect("/login");
Expand Down
12 changes: 12 additions & 0 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@
"queryLocation": "/sourceQueries/index_example_texon_only_source.rq"
}
},
{
"id": "1500",
"queryGroupId": "c-tst",
"queryLocation": "components_materials.rq",
"name": "Sources from an index file (requiring authentication)",
"description": "Query components (including details about materials) with the sources obtained from index files that require authentication to retrieve said sources.",
"sourcesIndex": {
"url": "http://localhost:8080/example/index-example-texon-only-AUTH",
"queryLocation": "/sourceQueries/index_example_texon_only_source_AUTH.rq"
}
},

{
"id": "2000",
"queryGroupId": "b-prj",
Expand Down
6 changes: 2 additions & 4 deletions src/dataProvider/SparqlDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,10 @@ const addComunicaContextSourcesFromSourcesIndex = async (sourcesIndex) => {
}else{
queryStringIndexSource = sourcesIndex.queryString;
}

const bindingsStream = await myEngine.queryBindings(queryStringIndexSource, {
sources: [sourcesIndex.url],
...generateContext({sources: [sourcesIndex.url]}),
});

await new Promise((resolve, reject) => {
bindingsStream.on('data', (bindings) => {
// the bindings should have exactly one key (any name is allowed) and we accept the value as a source
Expand All @@ -381,7 +380,6 @@ const addComunicaContextSourcesFromSourcesIndex = async (sourcesIndex) => {

return sourcesList;
};

/**
* Creates/extends a comunicaContext property in a query
* @param {object} query - the query element from the configuration
Expand Down

0 comments on commit 5870c72

Please sign in to comment.