Skip to content

Commit 5870c72

Browse files
authored
Merge pull request #145 from SolidLabResearch/fix/sources-from-indexFile-problem
Fix/sources from index file problem
2 parents fb444e0 + 5db57b1 commit 5870c72

File tree

8 files changed

+90
-7
lines changed

8 files changed

+90
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020

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

2425
## [1.2.1] - 2024-06-17
2526

cypress/e2e/sources-from-indexfile.cy.js

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe("Sources from index file", () => {
1212

1313
// Check that it indeed had 3 sources
1414
cy.get('.information-box').contains('Sources: 3');
15-
15+
1616
// Check if correct data is displayed
1717
cy.contains("http://www/example.com/data/component-c01");
1818
cy.contains("Component 1");
@@ -31,7 +31,7 @@ describe("Sources from index file", () => {
3131

3232
// Check that all 4 sources were used
3333
cy.get('.information-box').contains('Sources: 4');
34-
34+
3535
// Check if correct data is still displayed even if one source was unauthorized
3636
cy.contains("http://www/example.com/data/component-c01");
3737
cy.contains("Component 1");
@@ -50,11 +50,58 @@ describe("Sources from index file", () => {
5050

5151
// Check that the 4 sources were successfully merged
5252
cy.get('.information-box').contains('Sources: 4');
53-
53+
5454
// Check if correct data is still displayed even if one source was unauthorized and different sources were merged
5555
cy.contains("http://www/example.com/data/component-c01");
5656
cy.contains("Component 1");
5757
cy.contains("Material 1");
5858
});
5959

60+
it("Sources from an unauthorized source. Before and after log in.", () => {
61+
cy.visit("/");
62+
63+
cy.intercept('GET', 'http://localhost:8080/example/index-example-texon-only-AUTH').as('getRequest');
64+
65+
// Navigate to correct query
66+
cy.contains("For testing only").click();
67+
cy.contains("Sources from an index file (requiring authentication)").click();
68+
69+
// Wait for the request and assert the response
70+
cy.wait('@getRequest').then((interception) => {
71+
expect(interception.response.statusCode).to.equal(401);
72+
});
73+
74+
75+
cy.contains("http://www/example.com/data/component-c01").should("not.exist");
76+
cy.contains("Component 1").should("not.exist");
77+
cy.contains("Material 1").should("not.exist");
78+
79+
//log in
80+
cy.get('[aria-label="Profile"]').click();
81+
cy.contains('[role="menuitem"]', "Login").click();
82+
83+
cy.get('input[name="idp"]')
84+
.clear();
85+
cy.get('input[name="idp"]')
86+
.type("http://localhost:8080/example/profile/card#me");
87+
cy.contains("Login").click();
88+
89+
cy.get("input#email").type("[email protected]");
90+
cy.get("input#password").type("abc123");
91+
cy.contains("button", "Log in").click();
92+
cy.contains("button", "Authorize").click();
93+
94+
cy.url().should("eq", "http://localhost:5173/");
95+
96+
//now try again
97+
cy.contains("For testing only").click();
98+
cy.contains("Sources from an index file (requiring authentication)").click();
99+
100+
cy.contains("http://www/example.com/data/component-c01").should("not.exist");
101+
cy.contains("Component 1").should("exist");
102+
cy.contains("Material 1").should("exist");
103+
})
104+
105+
106+
60107
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
2+
3+
<#index-example> rdfs:seeAlso
4+
<http://localhost:8080/example/boms>,
5+
<http://localhost:8080/example/components>,
6+
<http://localhost:8080/example/materials>
7+
.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@prefix acl: <http://www.w3.org/ns/auth/acl#>.
2+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
3+
4+
<#owner>
5+
a acl:Authorization;
6+
acl:accessTo <./index-example-texon-only-AUTH>;
7+
acl:agent <http://localhost:8080/example/profile/card#me>;
8+
acl:mode acl:Read, acl:Write, acl:Control.
9+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
2+
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
3+
PREFIX example: <http://localhost:8080/example/index-example-texon-only-AUTH#>
4+
5+
SELECT ?object
6+
WHERE {
7+
example:index-example rdfs:seeAlso ?object .
8+
}

src/components/InteractionLayout/AuthenticationMenu/LogoutButton.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const LogoutButton = forwardRef((props, ref) => {
2323
function handleLogout(event) {
2424
event.preventDefault();
2525
if (isLoggedIn) {
26+
redirect("/");
2627
logout();
2728
} else {
2829
redirect("/login");

src/config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@
170170
"queryLocation": "/sourceQueries/index_example_texon_only_source.rq"
171171
}
172172
},
173+
{
174+
"id": "1500",
175+
"queryGroupId": "c-tst",
176+
"queryLocation": "components_materials.rq",
177+
"name": "Sources from an index file (requiring authentication)",
178+
"description": "Query components (including details about materials) with the sources obtained from index files that require authentication to retrieve said sources.",
179+
"sourcesIndex": {
180+
"url": "http://localhost:8080/example/index-example-texon-only-AUTH",
181+
"queryLocation": "/sourceQueries/index_example_texon_only_source_AUTH.rq"
182+
}
183+
},
184+
173185
{
174186
"id": "2000",
175187
"queryGroupId": "b-prj",

src/dataProvider/SparqlDataProvider.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,10 @@ const addComunicaContextSourcesFromSourcesIndex = async (sourcesIndex) => {
350350
}else{
351351
queryStringIndexSource = sourcesIndex.queryString;
352352
}
353-
353+
354354
const bindingsStream = await myEngine.queryBindings(queryStringIndexSource, {
355-
sources: [sourcesIndex.url],
355+
...generateContext({sources: [sourcesIndex.url]}),
356356
});
357-
358357
await new Promise((resolve, reject) => {
359358
bindingsStream.on('data', (bindings) => {
360359
// the bindings should have exactly one key (any name is allowed) and we accept the value as a source
@@ -381,7 +380,6 @@ const addComunicaContextSourcesFromSourcesIndex = async (sourcesIndex) => {
381380

382381
return sourcesList;
383382
};
384-
385383
/**
386384
* Creates/extends a comunicaContext property in a query
387385
* @param {object} query - the query element from the configuration

0 commit comments

Comments
 (0)