13
13
import io .whitefox .core .services .exceptions .TableNotFound ;
14
14
import io .whitefox .persistence .StorageManager ;
15
15
import io .whitefox .persistence .memory .InMemoryStorageManager ;
16
+ import jakarta .ws .rs .ForbiddenException ;
16
17
import java .util .Collections ;
17
18
import java .util .List ;
18
19
import java .util .Map ;
@@ -31,6 +32,7 @@ public class DeltaShareServiceTest {
31
32
WhitefoxAuthorization whitefoxAuthorization = new WhitefoxSimpleAuthorization ();
32
33
33
34
private static final Principal testPrincipal = new Principal ("Mr. Fox" );
35
+ private static final Principal badPrincipal = new Principal ("Mr. White" );
34
36
35
37
private static Share createShare (String name , String key , Map <String , Schema > schemas ) {
36
38
return new Share (name , key , schemas , testPrincipal , 0L );
@@ -52,6 +54,21 @@ public void listShares() {
52
54
Assertions .assertTrue (sharesWithNextToken .getToken ().isEmpty ());
53
55
}
54
56
57
+ @ Test
58
+ public void listSharesUnauthorized () {
59
+ var shares = List .of (new Share ("name" , "key" , Collections .emptyMap (), badPrincipal , 0L ));
60
+ StorageManager storageManager = new InMemoryStorageManager (shares );
61
+ DeltaSharesService deltaSharesService = new DeltaSharesServiceImpl (
62
+ storageManager ,
63
+ defaultMaxResults ,
64
+ tableLoaderFactory ,
65
+ fileSignerFactory ,
66
+ whitefoxAuthorization );
67
+ var sharesWithNextToken =
68
+ deltaSharesService .listShares (Optional .empty (), Optional .of (30 ), testPrincipal );
69
+ Assertions .assertEquals (0 , sharesWithNextToken .getContent ().size ());
70
+ }
71
+
55
72
@ Test
56
73
public void listSharesWithToken () {
57
74
var shares = List .of (createShare ("name" , "key" , Collections .emptyMap ()));
@@ -81,6 +98,18 @@ public void listSchemasOfEmptyShare() {
81
98
Assertions .assertTrue (resultSchemas .get ().getToken ().isEmpty ());
82
99
}
83
100
101
+ @ Test
102
+ public void listSchemasNoAuth () {
103
+ var shares = List .of (new Share ("name" , "key" , Collections .emptyMap (), badPrincipal , 0L ));
104
+ StorageManager storageManager = new InMemoryStorageManager (shares );
105
+ DeltaSharesService deltaSharesService = new DeltaSharesServiceImpl (
106
+ storageManager , 100 , tableLoaderFactory , fileSignerFactory , whitefoxAuthorization );
107
+ assertThrows (
108
+ ForbiddenException .class ,
109
+ () -> deltaSharesService .listSchemas (
110
+ "name" , Optional .empty (), Optional .empty (), testPrincipal ));
111
+ }
112
+
84
113
@ Test
85
114
public void listSchemas () {
86
115
var shares = List .of (createShare (
0 commit comments