-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
ServerConfigDocIT.java
214 lines (182 loc) · 8.22 KB
/
ServerConfigDocIT.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.server;
import java.io.IOException;
import javax.ws.rs.core.MediaType;
import org.junit.After;
import org.junit.Test;
import org.neo4j.server.configuration.ServerSettings;
import org.neo4j.server.rest.JaxRsResponse;
import org.neo4j.server.rest.RestRequest;
import org.neo4j.server.scripting.javascript.GlobalJavascriptInitializer;
import org.neo4j.test.server.ExclusiveServerTestBase;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.neo4j.server.helpers.CommunityServerBuilder.server;
import static org.neo4j.test.server.HTTP.POST;
public class ServerConfigDocIT extends ExclusiveServerTestBase
{
private CommunityNeoServer server;
@After
public void stopTheServer()
{
server.stop();
}
@Test
public void shouldPickUpPortFromConfig() throws Exception
{
final int NON_DEFAULT_PORT = 4321;
server = server().onPort( NON_DEFAULT_PORT )
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build();
server.start();
assertEquals( NON_DEFAULT_PORT, server.getWebServerPort() );
JaxRsResponse response = new RestRequest( server.baseUri() ).get();
assertThat( response.getStatus(), is( 200 ) );
response.close();
}
@Test
public void shouldPickupRelativeUrisForWebAdminAndWebAdminRest() throws IOException
{
String webAdminDataUri = "/a/different/data/uri/";
String webAdminManagementUri = "/a/different/management/uri/";
server = server().withRelativeWebDataAdminUriPath( webAdminDataUri )
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.withRelativeWebAdminUriPath( webAdminManagementUri )
.build();
server.start();
JaxRsResponse response = new RestRequest().get( "http://localhost:7474" + webAdminDataUri,
MediaType.TEXT_HTML_TYPE );
assertEquals( 200, response.getStatus() );
response = new RestRequest().get( "http://localhost:7474" + webAdminManagementUri );
assertEquals( 200, response.getStatus() );
response.close();
}
@Test
public void shouldGenerateWADLWhenExplicitlyEnabledInConfig() throws IOException
{
server = server().withProperty( ServerSettings.wadl_enabled.name(), "true" )
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build();
server.start();
JaxRsResponse response = new RestRequest().get( "http://localhost:7474/application.wadl",
MediaType.WILDCARD_TYPE );
assertEquals( 200, response.getStatus() );
assertEquals( "application/vnd.sun.wadl+xml", response.getHeaders().get( "Content-Type" ).iterator().next() );
assertThat( response.getEntity(), containsString( "<application xmlns=\"http://wadl.dev.java" +
".net/2009/02\">" ) );
}
@Test
public void shouldNotGenerateWADLWhenNotExplicitlyEnabledInConfig() throws IOException
{
server = server()
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build();
server.start();
JaxRsResponse response = new RestRequest().get( "http://localhost:7474/application.wadl",
MediaType.WILDCARD_TYPE );
assertEquals( 404, response.getStatus() );
}
@Test
public void shouldNotGenerateWADLWhenExplicitlyDisabledInConfig() throws IOException
{
server = server().withProperty( ServerSettings.wadl_enabled.name(), "false" )
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build();
server.start();
JaxRsResponse response = new RestRequest().get( "http://localhost:7474/application.wadl",
MediaType.WILDCARD_TYPE );
assertEquals( 404, response.getStatus() );
}
@Test
public void shouldEnableWebadminConsoleByDefault() throws IOException
{
// Given
server = server().usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() ).build();
server.start();
// When & then
assertEquals( 200, new RestRequest().get( "http://localhost:7474/db/manage/server/console" ).getStatus() );
}
@Test
public void shouldDisableWebadminConsoleWhenAskedTo() throws IOException
{
// Given
server = server().withProperty( ServerSettings.webadmin_enabled.name(), "false" )
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build();
server.start();
// When & then
assertEquals( 404, new RestRequest().get( "http://localhost:7474/db/manage/server/console" ).getStatus() );
}
@Test
public void shouldHaveSandboxingEnabledByDefault() throws Exception
{
// Given
server = server()
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build();
server.start();
String node = POST( server.baseUri().toASCIIString() + "db/data/node" ).location();
// When
JaxRsResponse response = new RestRequest().post( node + "/traverse/node", "{\n" +
" \"order\" : \"breadth_first\",\n" +
" \"return_filter\" : {\n" +
" \"body\" : \"position.getClass().getClassLoader()\",\n" +
" \"language\" : \"javascript\"\n" +
" },\n" +
" \"prune_evaluator\" : {\n" +
" \"body\" : \"position.getClass().getClassLoader()\",\n" +
" \"language\" : \"javascript\"\n" +
" },\n" +
" \"uniqueness\" : \"node_global\",\n" +
" \"relationships\" : [ {\n" +
" \"direction\" : \"all\",\n" +
" \"type\" : \"knows\"\n" +
" }, {\n" +
" \"direction\" : \"all\",\n" +
" \"type\" : \"loves\"\n" +
" } ],\n" +
" \"max_depth\" : 3\n" +
"}", MediaType.APPLICATION_JSON_TYPE );
// Then
assertEquals( 400, response.getStatus() );
}
/*
* We can't actually test that disabling sandboxing works, because of the set-once global nature of Rhino
* security. Instead, we test here that changing it triggers the expected exception, letting us know that
* the code that *would* have set it to disabled realizes it has already been set to sandboxed.
*
* This at least lets us know that the configuration attribute gets picked up and used.
*/
@Test(expected = RuntimeException.class)
public void shouldBeAbleToDisableSandboxing() throws Exception
{
// NOTE: This has to be initialized to sandboxed, because it can only be initialized once per JVM session,
// and all other tests depend on it being sandboxed.
GlobalJavascriptInitializer.initialize( GlobalJavascriptInitializer.Mode.SANDBOXED );
server = server().withProperty( ServerSettings.script_sandboxing_enabled.name(), "false" )
.usingDataDir( folder.directory( name.getMethodName() ).getAbsolutePath() )
.build();
// When
server.start();
}
}