17
17
18
18
package org .openqa .selenium .netty .server ;
19
19
20
+ import static org .assertj .core .api .Assertions .assertThat ;
21
+ import static org .junit .Assert .assertEquals ;
22
+ import static org .junit .Assert .assertNull ;
23
+ import static org .junit .Assert .assertTrue ;
24
+ import static org .openqa .selenium .remote .http .Contents .utf8String ;
25
+ import static org .openqa .selenium .remote .http .HttpMethod .DELETE ;
26
+ import static org .openqa .selenium .remote .http .HttpMethod .GET ;
27
+
20
28
import com .google .common .collect .ImmutableMap ;
21
29
22
- import org .junit .Ignore ;
23
30
import org .junit .Test ;
24
31
import org .openqa .selenium .grid .config .CompoundConfig ;
25
32
import org .openqa .selenium .grid .config .Config ;
34
41
import java .net .URL ;
35
42
import java .util .concurrent .atomic .AtomicInteger ;
36
43
37
- import static org .assertj .core .api .Assertions .assertThat ;
38
- import static org .junit .Assert .assertEquals ;
39
- import static org .junit .Assert .assertTrue ;
40
- import static org .openqa .selenium .remote .http .Contents .utf8String ;
41
- import static org .openqa .selenium .remote .http .HttpMethod .DELETE ;
42
- import static org .openqa .selenium .remote .http .HttpMethod .GET ;
43
-
44
44
public class NettyServerTest {
45
45
46
46
/**
@@ -81,17 +81,13 @@ public void ensureMultipleCallsWorkAsExpected() {
81
81
82
82
@ Test
83
83
public void shouldDisableAllowOrigin () {
84
- // TODO: Server setup
85
84
Server <?> server = new NettyServer (
86
- new BaseServerOptions (
87
- new MapConfig (
88
- ImmutableMap .of ("server" , ImmutableMap .of ("port" , PortProber .findFreePort ())))),
89
- req -> {
90
- return new HttpResponse ().setContent (utf8String ("Count is " ));
91
- }
85
+ new BaseServerOptions (
86
+ new MapConfig (
87
+ ImmutableMap .of ("server" , ImmutableMap .of ("port" , PortProber .findFreePort ())))),
88
+ req -> new HttpResponse ().setContent (utf8String ("Count is " ))
92
89
).start ();
93
90
94
- // TODO: Client setup
95
91
URL url = server .getUrl ();
96
92
HttpClient client = HttpClient .Factory .createDefault ().createClient (url );
97
93
HttpRequest request = new HttpRequest (DELETE , "/session" );
@@ -100,50 +96,40 @@ public void shouldDisableAllowOrigin() {
100
96
request .setHeader ("Accept" , "*/*" );
101
97
HttpResponse response = client .execute (request );
102
98
103
- // TODO: Assertion
104
- assertEquals ("Access-Control-Allow-Credentials should be null" , null ,
105
- response .getHeader ("Access-Control-Allow-Credentials" ));
106
-
107
- assertEquals ("Access-Control-Allow-Origin should be null" ,
108
- null ,
109
- response .getHeader ("Access-Control-Allow-Origin" ));
99
+ assertNull ("Access-Control-Allow-Origin should be null" ,
100
+ response .getHeader ("Access-Control-Allow-Origin" ));
110
101
}
111
102
112
103
@ Test
113
- @ Ignore
114
104
public void shouldAllowCORS () {
115
- // TODO: Server setup
116
105
Config cfg = new CompoundConfig (
117
- new MapConfig (ImmutableMap .of ("server" , ImmutableMap .of ("allow-cors" , "true" ))));
106
+ new MapConfig (ImmutableMap .of ("server" , ImmutableMap .of ("allow-cors" , "true" ))));
118
107
BaseServerOptions options = new BaseServerOptions (cfg );
119
108
assertTrue ("Allow CORS should be enabled" , options .getAllowCORS ());
120
109
121
110
// TODO: Server setup
122
111
Server <?> server = new NettyServer (
123
- options ,
124
- req -> new HttpResponse ()
112
+ options ,
113
+ req -> new HttpResponse ()
125
114
).start ();
126
115
127
- // TODO: Client setup
128
116
URL url = server .getUrl ();
129
117
HttpClient client = HttpClient .Factory .createDefault ().createClient (url );
130
118
HttpRequest request = new HttpRequest (DELETE , "/session" );
131
- String exampleUrl = "http://www.example.com" ;
132
- request .setHeader ("Origin" , exampleUrl );
119
+ request .setHeader ("Origin" , "http://www.example.com" );
133
120
request .setHeader ("Accept" , "*/*" );
134
121
HttpResponse response = client .execute (request );
135
122
136
- // TODO: Assertion
137
- assertEquals ("Access-Control-Allow-Credentials should be true" , "true" ,
138
- response .getHeader ("Access-Control-Allow-Credentials" ));
139
-
140
- assertEquals ("Access-Control-Allow-Origin should be equal to origin in request header" ,
141
- exampleUrl ,
142
- response .getHeader ("Access-Control-Allow-Origin" ));
123
+ assertEquals (
124
+ "Access-Control-Allow-Origin should be equal to origin in request header" ,
125
+ "*" ,
126
+ response .getHeader ("Access-Control-Allow-Origin" ));
143
127
}
144
128
145
129
private void outputHeaders (HttpResponse res ) {
146
- res .getHeaderNames ().forEach (name ->
147
- res .getHeaders (name ).forEach (value -> System .out .printf ("%s -> %s\n " , name , value )));
130
+ res .getHeaderNames ()
131
+ .forEach (name ->
132
+ res .getHeaders (name )
133
+ .forEach (value -> System .out .printf ("%s -> %s\n " , name , value )));
148
134
}
149
135
}
0 commit comments