Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.

Commit 0bf6750

Browse files
committed
add test cases
1 parent 8c95ef7 commit 0bf6750

File tree

7 files changed

+359
-21
lines changed

7 files changed

+359
-21
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
## [Unreleased]
8+
### Added
9+
10+
### Changed
11+
12+
13+
## 0.1.2 - 2016-10-10
14+
### Added
15+
- Test cases
16+
17+
### Changed
18+
- Update exception handling with ApiException
19+
- Upgrade to framework 0.1.7
20+
- Remove several config files that are not used
21+
- Add status.json config for additional codes for OAuth2
22+
23+
24+
## 0.1.1 - 2016-09-19
25+
### Added
26+
27+
### Changed
28+
- Upgrade to framework 0.1.2
29+
30+
31+
## 0.1.0 - 2016-08-16
32+
### Added
33+
- Code Handler
34+
- Token Handler

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.networknt</groupId>
77
<artifactId>oauth2</artifactId>
88
<packaging>jar</packaging>
9-
<version>0.1.2-SNAPSHOT</version>
9+
<version>0.1.2</version>
1010
<name>oauth2</name>
1111

1212
<properties>
@@ -116,6 +116,12 @@
116116
<version>${version.junit}</version>
117117
<scope>test</scope>
118118
</dependency>
119+
<dependency>
120+
<groupId>org.apache.httpcomponents</groupId>
121+
<artifactId>httpclient</artifactId>
122+
<version>${version.httpclient}</version>
123+
<scope>test</scope>
124+
</dependency>
119125

120126
</dependencies>
121127

src/main/java/com/networknt/oauth/handler/CodeHandler.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public CodeHandler(ObjectMapper objectMapper) {
3131
this.objectMapper = objectMapper;
3232
}
3333

34-
public void handleRequest(HttpServerExchange exchange) throws ApiException {
34+
public void handleRequest(HttpServerExchange exchange) throws Exception {
3535
exchange.getResponseHeaders().put(
3636
Headers.CONTENT_TYPE, "application/json");
3737

@@ -49,15 +49,22 @@ public void handleRequest(HttpServerExchange exchange) throws ApiException {
4949
String responseType = params.get("response_type");
5050
String clientId = params.get("client_id");
5151
if(responseType == null || clientId == null) {
52-
throw new ApiException(new Status(INVALID_CODE_REQUEST));
52+
Status status = new Status(INVALID_CODE_REQUEST);
53+
exchange.setStatusCode(status.getStatusCode());
54+
exchange.getResponseSender().send(status.toString());
55+
return;
5356
} else {
5457
if(!"code".equals(responseType)) {
55-
throw new ApiException(new Status(INVALID_RESPONSE_TYPE, responseType));
58+
Status status = new Status(INVALID_RESPONSE_TYPE, responseType);
59+
exchange.setStatusCode(status.getStatusCode());
60+
exchange.getResponseSender().send(status.toString());
5661
} else {
5762
// check if the client_id is valid
5863
Map<String, Object> cMap = (Map<String, Object>)TokenHandler.clients.get(clientId);
5964
if(cMap == null) {
60-
throw new ApiException(new Status(CLIENT_ID_NOTFOUND, clientId));
65+
Status status = new Status(CLIENT_ID_NOTFOUND, clientId);
66+
exchange.setStatusCode(status.getStatusCode());
67+
exchange.getResponseSender().send(status.toString());
6168
} else {
6269
// generate auth code
6370
String code = Util.getUUID();

src/main/java/com/networknt/oauth/handler/TokenHandler.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ public void handleRequest(HttpServerExchange exchange) throws ApiException {
6262
}
6363
}
6464
} catch (Exception e) {
65-
throw new ApiException(new Status(UNABLE_TO_PARSE_FORM_DATA, e.getMessage()));
65+
Status status = new Status(UNABLE_TO_PARSE_FORM_DATA, e.getMessage());
66+
exchange.setStatusCode(status.getStatusCode());
67+
exchange.getResponseSender().send(status.toString());
68+
return;
6669
}
6770
try {
6871
if("client_credentials".equals(formMap.get("grant_type"))) {
@@ -73,9 +76,16 @@ public void handleRequest(HttpServerExchange exchange) throws ApiException {
7376
Status status = new Status(UNSUPPORTED_GRANT_TYPE, formMap.get("grant_type"));
7477
exchange.setStatusCode(status.getStatusCode());
7578
exchange.getResponseSender().send(status.toString());
79+
return;
7680
}
7781
} catch (JsonProcessingException e) {
78-
throw new ApiException(new Status(JSON_PROCESSING_EXCEPTION, e.getMessage()));
82+
Status status = new Status(JSON_PROCESSING_EXCEPTION, e.getMessage());
83+
exchange.setStatusCode(status.getStatusCode());
84+
exchange.getResponseSender().send(status.toString());
85+
return;
86+
} catch (ApiException e) {
87+
exchange.setStatusCode(e.getStatus().getStatusCode());
88+
exchange.getResponseSender().send(e.getStatus().toString());
7989
}
8090
}
8191

src/test/java/com/networknt/oauth/CodeHandlerTest.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)