@@ -490,8 +490,11 @@ void testFilterResponseNoControl() {
490490 @ Test
491491 void testFilterResponseWithControl () {
492492 final MultivaluedMap <String , Object > headers = new MultivaluedHashMap <>();
493+ final MultivaluedMap <String , String > stringHeaders = new MultivaluedHashMap <>();
494+ stringHeaders .putSingle ("Link" , "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\" type\" " );
493495 when (mockResponseContext .getStatusInfo ()).thenReturn (OK );
494496 when (mockResponseContext .getHeaders ()).thenReturn (headers );
497+ when (mockResponseContext .getStringHeaders ()).thenReturn (stringHeaders );
495498 when (mockContext .getProperty (eq (WebAcFilter .SESSION_WEBAC_MODES )))
496499 .thenReturn (new AuthorizedModes (effectiveAcl , allModes ));
497500
@@ -510,6 +513,94 @@ void testFilterResponseWithControl() {
510513 link .getRels ().contains (Trellis .effectiveAcl .getIRIString ())));
511514 }
512515
516+ @ Test
517+ void testFilterResponseWithControl2 () {
518+ final MultivaluedMap <String , Object > headers = new MultivaluedHashMap <>();
519+ final MultivaluedMap <String , String > stringHeaders = new MultivaluedHashMap <>();
520+ stringHeaders .putSingle ("Link" , "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\" blah\" " );
521+ when (mockResponseContext .getStatusInfo ()).thenReturn (OK );
522+ when (mockResponseContext .getHeaders ()).thenReturn (headers );
523+ when (mockResponseContext .getStringHeaders ()).thenReturn (stringHeaders );
524+ when (mockContext .getProperty (eq (WebAcFilter .SESSION_WEBAC_MODES )))
525+ .thenReturn (new AuthorizedModes (effectiveAcl , allModes ));
526+
527+ final WebAcFilter filter = new WebAcFilter ();
528+ filter .setAccessService (mockWebAcService );
529+
530+ assertTrue (headers .isEmpty ());
531+ filter .filter (mockContext , mockResponseContext );
532+ assertFalse (headers .isEmpty ());
533+
534+ final List <Object > links = headers .get ("Link" );
535+ assertTrue (links .stream ().map (Link .class ::cast ).anyMatch (link ->
536+ link .getRels ().contains ("acl" ) && "/?ext=acl" .equals (link .getUri ().toString ())));
537+ assertTrue (links .stream ().map (Link .class ::cast ).anyMatch (link ->
538+ "/?ext=acl" .equals (link .getUri ().toString ()) &&
539+ link .getRels ().contains (Trellis .effectiveAcl .getIRIString ())));
540+ }
541+
542+ @ Test
543+ void testFilterResourceResponseWithControl () {
544+ final IRI localEffectiveAcl = rdf .createIRI (TRELLIS_DATA_PREFIX + "resource" );
545+ final MultivaluedMap <String , Object > headers = new MultivaluedHashMap <>();
546+ final MultivaluedMap <String , String > stringHeaders = new MultivaluedHashMap <>();
547+ stringHeaders .putSingle ("Link" , "<http://www.w3.org/ns/ldp#RDFSource>; rel=\" type\" " );
548+ when (mockResponseContext .getStatusInfo ()).thenReturn (OK );
549+ when (mockResponseContext .getHeaders ()).thenReturn (headers );
550+ when (mockResponseContext .getStringHeaders ()).thenReturn (stringHeaders );
551+ when (mockUriInfo .getPath ()).thenReturn ("/resource" );
552+ when (mockWebAcService .getAuthorizedModes (any (IRI .class ), any (Session .class )))
553+ .thenReturn (new AuthorizedModes (localEffectiveAcl , allModes ));
554+
555+ when (mockContext .getProperty (eq (WebAcFilter .SESSION_WEBAC_MODES )))
556+ .thenReturn (new AuthorizedModes (localEffectiveAcl , allModes ));
557+
558+ final WebAcFilter filter = new WebAcFilter ();
559+ filter .setAccessService (mockWebAcService );
560+
561+ assertTrue (headers .isEmpty ());
562+ filter .filter (mockContext , mockResponseContext );
563+ assertFalse (headers .isEmpty ());
564+
565+ final List <Object > links = headers .get ("Link" );
566+ assertTrue (links .stream ().map (Link .class ::cast ).anyMatch (link ->
567+ link .getRels ().contains ("acl" ) && "/resource?ext=acl" .equals (link .getUri ().toString ())));
568+ assertTrue (links .stream ().map (Link .class ::cast ).anyMatch (link ->
569+ "/resource?ext=acl" .equals (link .getUri ().toString ()) &&
570+ link .getRels ().contains (Trellis .effectiveAcl .getIRIString ())));
571+ }
572+
573+ @ Test
574+ void testFilterContainerResponseWithControl () {
575+ final IRI localEffectiveAcl = rdf .createIRI (TRELLIS_DATA_PREFIX + "container" );
576+ final MultivaluedMap <String , Object > headers = new MultivaluedHashMap <>();
577+ final MultivaluedMap <String , String > stringHeaders = new MultivaluedHashMap <>();
578+ stringHeaders .putSingle ("Link" , "<http://www.w3.org/ns/ldp#BasicContainer>; rel=\" type\" " );
579+ when (mockResponseContext .getStatusInfo ()).thenReturn (OK );
580+ when (mockResponseContext .getHeaders ()).thenReturn (headers );
581+ when (mockResponseContext .getStringHeaders ()).thenReturn (stringHeaders );
582+ when (mockUriInfo .getPath ()).thenReturn ("/container/" );
583+ when (mockWebAcService .getAuthorizedModes (any (IRI .class ), any (Session .class )))
584+ .thenReturn (new AuthorizedModes (localEffectiveAcl , allModes ));
585+
586+ when (mockContext .getProperty (eq (WebAcFilter .SESSION_WEBAC_MODES )))
587+ .thenReturn (new AuthorizedModes (localEffectiveAcl , allModes ));
588+
589+ final WebAcFilter filter = new WebAcFilter ();
590+ filter .setAccessService (mockWebAcService );
591+
592+ assertTrue (headers .isEmpty ());
593+ filter .filter (mockContext , mockResponseContext );
594+ assertFalse (headers .isEmpty ());
595+
596+ final List <Object > links = headers .get ("Link" );
597+ assertTrue (links .stream ().map (Link .class ::cast ).anyMatch (link ->
598+ link .getRels ().contains ("acl" ) && "/container/?ext=acl" .equals (link .getUri ().toString ())));
599+ assertTrue (links .stream ().map (Link .class ::cast ).anyMatch (link ->
600+ "/container/?ext=acl" .equals (link .getUri ().toString ()) &&
601+ link .getRels ().contains (Trellis .effectiveAcl .getIRIString ())));
602+ }
603+
513604 @ Test
514605 void testFilterResponseDelete () {
515606 final MultivaluedMap <String , Object > headers = new MultivaluedHashMap <>();
@@ -530,8 +621,10 @@ void testFilterResponseDelete() {
530621 @ Test
531622 void testFilterResponseBaseUrl () {
532623 final MultivaluedMap <String , Object > headers = new MultivaluedHashMap <>();
624+ final MultivaluedMap <String , String > stringHeaders = new MultivaluedHashMap <>();
533625 when (mockResponseContext .getStatusInfo ()).thenReturn (OK );
534626 when (mockResponseContext .getHeaders ()).thenReturn (headers );
627+ when (mockResponseContext .getStringHeaders ()).thenReturn (stringHeaders );
535628 when (mockUriInfo .getPath ()).thenReturn ("/path" );
536629 when (mockContext .getProperty (eq (WebAcFilter .SESSION_WEBAC_MODES )))
537630 .thenReturn (new AuthorizedModes (effectiveAcl , allModes ));
@@ -555,10 +648,12 @@ void testFilterResponseBaseUrl() {
555648 void testFilterResponseWebac2 () {
556649 final MultivaluedMap <String , Object > headers = new MultivaluedHashMap <>();
557650 final MultivaluedMap <String , String > params = new MultivaluedHashMap <>();
651+ final MultivaluedMap <String , String > stringHeaders = new MultivaluedHashMap <>();
558652 params .add ("ext" , "foo" );
559653 params .add ("ext" , "acl" );
560654 when (mockResponseContext .getStatusInfo ()).thenReturn (OK );
561655 when (mockResponseContext .getHeaders ()).thenReturn (headers );
656+ when (mockResponseContext .getStringHeaders ()).thenReturn (stringHeaders );
562657 when (mockUriInfo .getQueryParameters ()).thenReturn (params );
563658 when (mockUriInfo .getPath ()).thenReturn ("path/" );
564659 when (mockContext .getProperty (eq (WebAcFilter .SESSION_WEBAC_MODES )))
0 commit comments