@@ -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} ) ;
0 commit comments