Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(close-potential-network-leaks) #19

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/main/java/com/wire/helium/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,13 @@ public boolean deleteConversation(UUID teamId) throws HttpException {
header(HttpHeaders.AUTHORIZATION, bearer(token)).
delete();

if (response.getStatus() >= 400) {
if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error("DeleteConversation http error: %s, status: %d", msgError, response.getStatus());
throw new HttpException(msgError, response.getStatus());
}

response.close();
return response.getStatus() == 200;
}

Expand All @@ -393,11 +394,13 @@ public void addService(UUID serviceId, UUID providerId) throws HttpException {
header(HttpHeaders.AUTHORIZATION, bearer(token)).
post(Entity.entity(service, MediaType.APPLICATION_JSON));

if (response.getStatus() >= 400) {
if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error("AddService http error: %s, status: %d", msgError, response.getStatus());
throw new HttpException(msgError, response.getStatus());
}

response.close();
}

@Override
Expand All @@ -413,11 +416,13 @@ public void addParticipants(QualifiedId... userIds) throws HttpException {
header(HttpHeaders.AUTHORIZATION, bearer(token)).
post(Entity.entity(newConv, MediaType.APPLICATION_JSON));

if (response.getStatus() >= 400) {
if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error("AddParticipants http error: %s, status: %d", msgError, response.getStatus());
throw new HttpException(msgError, response.getStatus());
}

response.close();
}

@Override
Expand Down Expand Up @@ -481,11 +486,13 @@ public void leaveConversation(QualifiedId user) throws HttpException {
.header(HttpHeaders.AUTHORIZATION, bearer(token))
.delete();

if (response.getStatus() >= 400) {
if (isErrorResponse(response.getStatus())) {
String msgError = response.readEntity(String.class);
Logger.error("LeaveConversation http error: %s, status: %d", msgError, response.getStatus());
throw new HttpException(msgError, response.getStatus());
}

response.close();
}

/**
Expand Down Expand Up @@ -571,6 +578,7 @@ public NotificationList retrieveNotifications(String client, UUID since, int siz
final NotificationList emptyNotifications = new NotificationList();
emptyNotifications.hasMore = false;
emptyNotifications.notifications = new ArrayList<>();
response.close();
return emptyNotifications;
} else if (status == 401) { // Nginx returns text/html for 401. Cannot deserialize as json
response.readEntity(String.class);
Expand Down Expand Up @@ -703,9 +711,10 @@ public void uploadClientPublicKey(String clientId, ClientUpdate clientUpdate) th

Logger.error(errorMessage);
throw new RuntimeException(errorResponse);
} else if(isSuccessResponse(response.getStatus())) {
Logger.info("uploadClientPublicKey success for clientId: %s", clientId);
}

Logger.info("uploadClientPublicKey success for clientId: %s", clientId);
response.close();
}

/**
Expand Down Expand Up @@ -734,15 +743,16 @@ public void uploadClientKeyPackages(String clientId, KeyPackageUpdate keyPackage
if (isErrorResponse(response.getStatus())) {
String errorResponse = response.readEntity(String.class);
String errorMessage = String.format(
"getConversationGroupInfo error: %s, clientId: %s, status: %d",
"uploadClientKeyPackages error: %s, clientId: %s, status: %d",
errorResponse, clientId, response.getStatus()
);

Logger.error(errorMessage);
throw new RuntimeException(errorResponse);
} else if(isSuccessResponse(response.getStatus())) {
Logger.info("uploadClientKeyPackages success for clientId: %s", clientId);
}

Logger.info("uploadClientKeyPackages success for clientId: %s", clientId);
response.close();
}

@Override
Expand Down Expand Up @@ -778,6 +788,7 @@ public void commitMlsBundle(byte[] commitBundle) {

if (isSuccessResponse(response.getStatus())) {
Logger.info("commitMlsBundle success.");
response.close();
return;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/wire/helium/LoginClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public void logout(Cookie cookie, String token) throws HttpException {
} else if (status >= 400) {
throw response.readEntity(HttpException.class);
}

response.close();
}

public void removeCookies(String token, String password) throws HttpException {
Expand All @@ -255,6 +257,7 @@ public void removeCookies(String token, String password) throws HttpException {
throw response.readEntity(HttpException.class);
}

response.close();
}

@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down