Skip to content

Commit

Permalink
chore(release): v0.0.30 (#66)
Browse files Browse the repository at this point in the history
* [ci skip] chore(release): 0.0.13

* feat: Normalize method responses (#36)

* [ci skip] chore(release): 0.0.14

* chore: JSON library (#37)

* chore: Add org.json dependency

* chore: Add JSON usage example

* [ci skip] chore(release): 0.0.15

* feat: Config from env vars (#38)

* feat: Get conf from env vars

* docs: Add CLI.md document

* docs: Link docs in README

* feat: Add default ENV vars to Dockerfile for convenience

* fix: Change worker RMI default port

* [ci skip] chore(release): 0.0.16

* feat: adding register implementation and some changes in .gitignore (#35)

* feat: adding register implementation and some changes in .gitignore

* fix: fixing format inconsistencies

* feat: changing and upgrading res in success

* fix: upgrading requests and responses

* fix: changing parameter from pass to password

* fix: changing url format

* fix: clang format

* fix: True on success

* fix: Use Config class for env vars

---------

Co-authored-by: woynert

* [ci skip] chore(release): 0.0.17

* Feat login (#40)

* Feat login without tests

* Apply formatting

* [ci skip] chore(release): 0.0.18

* docs: SOAP OpenAPI specification (#41)

* docs: Add open api specification

* docs: Add API definition to README.md

* docs: Improve CLI.md examples

* refactor: Redesign request / response types

* chore: Update python sample client

* chore: Update submodule

* chore: Use error instead of success

* chore: Apply requested changes

* [ci skip] chore(release): 0.0.19

* feat: Upload File, Tests, Restructure (#42)

* feat: createFile handler

* fix: Use byte primitive

* chore: Remove RMI demo from App.java

* chore: apply clang-format

* feat: Abstract rmi connection

* chore: Update rmi lib

* chore: Utils package

* feat: Auth abstraction

* feat: Authenticate jwt on upload file

* feat: Get user's UUID

* feat: Get file mimetype from bytes

* fix: Make metadata & auth services use a single postgres instance

* feat: Pre declare userUUID

* fix: Get userUUID from token

* docs: Update env vars default values

* feat(upload-file): save metadata

* fix: ManagerRMI interface import

* chore: Remove debug msgs

* refactor: Switch SOAP data types sufix to prefix

* chore: Remove debug msgs

* chore: Update RMI submodule

* refactor: Redesign request / response types

* fix: Adapt current service implementation with new interface design

* docs: Add open api specification

* docs: Add API definition to README.md

* docs: Improve CLI.md examples

* refactor: Redesign request / response types

* chore: Update python sample client

* chore: Update submodule

* chore: update submodule

* fix: Typo in request type

* feat(upload-file): Add file size limits

* chore: Use error instead of success

* fix: Simplify http requests

* refactor: External services: Managers to Services

* refactor: Separate SOAP request handlers as controllers

* chore: Add http codes to auth method

* feat: Add http codes to Metadata save file

* feat: Better http code handling

* feat: Add ResStatus generic downcast support

* feat: Validate field types

* feat: Adapt getUserUUID method to a ResStatus response

* test: Test util to tweak configurations

* fix: controller exit codes

* test: Authorization service abstraction

* test: FileIO upload-file

* docs: Update README & API spec

* test: show realtime std, err on tests execution

* feat: update python client demo

* chore: Update docker compose with worker service & adminer

* docs: Update default MetadataURI env var

* chore: Use worker release image

* ci: Fix workflows: testing, coverage

* fix: Do not assume api sufix

* fix: Exclude tests on Dockerfile build

* [ci skip] chore(release): 0.0.20

* Update login and Add tests (#47)

* Updeate return code and test

* Fixes Implemented

* fix: Update RMI module

* Fix Format

* Fix

* Test: update message

---------

Co-authored-by: woynert <[email protected]>

* [ci skip] chore(release): 0.0.21

* feat: download file (#46)

* feat: createFile handler

* fix: Use byte primitive

* chore: Remove RMI demo from App.java

* chore: apply clang-format

* feat: Abstract rmi connection

* chore: Update rmi lib

* chore: Utils package

* feat: Auth abstraction

* feat: Authenticate jwt on upload file

* feat: Get user's UUID

* feat: Get file mimetype from bytes

* fix: Make metadata & auth services use a single postgres instance

* feat: Pre declare userUUID

* fix: Get userUUID from token

* docs: Update env vars default values

* feat(upload-file): save metadata

* fix: ManagerRMI interface import

* chore: Remove debug msgs

* refactor: Switch SOAP data types sufix to prefix

* chore: Remove debug msgs

* chore: Update RMI submodule

* refactor: Redesign request / response types

* fix: Adapt current service implementation with new interface design

* docs: Add open api specification

* docs: Add API definition to README.md

* docs: Improve CLI.md examples

* refactor: Redesign request / response types

* chore: Update python sample client

* chore: Update submodule

* chore: update submodule

* fix: Typo in request type

* feat(upload-file): Add file size limits

* chore: Use error instead of success

* fix: Simplify http requests

* refactor: External services: Managers to Services

* refactor: Separate SOAP request handlers as controllers

* chore: Add http codes to auth method

* feat: Add http codes to Metadata save file

* feat: Better http code handling

* feat: Add ResStatus generic downcast support

* feat: Validate field types

* feat: Adapt getUserUUID method to a ResStatus response

* test: Test util to tweak configurations

* fix: controller exit codes

* test: Authorization service abstraction

* test: FileIO upload-file

* docs: Update README & API spec

* test: show realtime std, err on tests execution

* feat: update python client demo

* chore: Update docker compose with worker service & adminer

* docs: Update default MetadataURI env var

* chore: Use worker release image

* ci: Fix workflows: testing, coverage

* fix: Do not assume api sufix

* fix: Exclude tests on Dockerfile build

* chore: Update RMI types to use UUID

* feat(ServiceMetadata): canRead wrapper added

* feat(ServiceMetadata): getFileMetadata wrapper added

* chore: update fileDownload res/req types

* feat: fileDownload service implementation

* chore: Add RMI Streaming library

* feat(fileDownload): Add 404 code case

* fix: Login return code

* test: Add new ASCII generator

* test: Update uploadFile test to save relevant data for other tests

* test: Add fileDownload tests

* chore: Remove debug messages & unclutter test output

* fix: Add workaround issue Metadata#74

* chore: increase buffer size for data streaming

* chore: update submodule

* feat: Update demo python SOAP client

* fix: Nullable extension result

* fix: Give time for file to finish uploading before next test

* ci: run test workflows on PRs against main

* chore: Improve cli client (#55)

* refactor: Make cli client reusable
---------

Co-authored-by: woynert <[email protected]>

---------

Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]>

* [ci skip] chore(release): 0.0.22

* [ci skip] chore(release): 0.0.23

* feat: file check ready (#57)

* fix: Remove duplicated uri chained method

* feat: add file check controller implementation

* test: add file_check tests

* feat: make format script default to write

* feat: use serviceMetadata existing implementation for fileCheck

* test(file check): add tests for case 400 and 401

* style: apply clang-format

* [ci skip] chore(release): 0.0.24

* chore: Rename soap endpoint (#59)

* chore: update python-cli soap endpoint

* chore: Update endpoint from /service to /gw/service

* [ci skip] chore(release): 0.0.25

* feat: challenge endpoint (#56)

* feat: Auth refresh service implementation

* feat: Auth refresh query implementation

* fix: Additional property attach not allowed on postgres-admin service

* docs: Auth refresh update on api specification

* feat: Auth refresh test implementaion

* fix: Fix typos on controller

* docs: Update response schema on auth refresh

* feat: Update soap python client for auth refresh

* Fix: Code formatting

* style: adjust spaces

---------

Co-authored-by: woynert <[email protected]>

* [ci skip] chore(release): 0.0.26

* Fix: Delete Unnecesary resFileNew (#63)

* [ci skip] chore(release): 0.0.27

* test: Add tests for register method (#60)

* feat: init test to register and fixing format issues in CtrlAccountRegister

* fix: changing location of register test

* fix: adding requested changes in code and tests

* fix: validating format in code

* [ci skip] chore(release): 0.0.28

* Feat: share file feature (#61)

* fix: deleting attach from docker

* feat: starting share-file feat changes

* feat: init of adding error and msg according with statuscode

* feat: some last adjustments for share file feat

* feat: share file feat concluded and test of it added

* fix: deleting repeated code and adding a check for errors after request otherUserUUID

* fix: deleting unnecessary checkFile action in test

* chore: remove unused import

---------

Co-authored-by: woynert <[email protected]>

* [ci skip] chore(release): 0.0.29

* [ci skip] chore(release): 0.0.30

---------

Co-authored-by: Antonio Donis <[email protected]>
Co-authored-by: Woynert <[email protected]>
Co-authored-by: Andres David Bonilla Higuera <[email protected]>
Co-authored-by: woynert <[email protected]>
Co-authored-by: Pedro Andrés Chaparro Quintero <[email protected]>
Co-authored-by: Cristian Julian Muñoz Buenahora <[email protected]>
Co-authored-by: woynert <[email protected]>
  • Loading branch information
8 people authored Oct 8, 2023
1 parent 59506eb commit 405ec70
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 22 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### 0.0.30 (2023-10-08)

### 0.0.29 (2023-10-08)


### Features

* share file feature ([#61](https://github.com/hawks-atlanta/gateway-java/issues/61)) ([ff0efa6](https://github.com/hawks-atlanta/gateway-java/commit/ff0efa69503dbedc6ce1b7f6f50d4b0082b1abe6))

### 0.0.28 (2023-10-08)

### 0.0.27 (2023-10-07)


### Bug Fixes

* Delete Unnecesary resFileNew ([#63](https://github.com/hawks-atlanta/gateway-java/issues/63)) ([4eea954](https://github.com/hawks-atlanta/gateway-java/commit/4eea9541c85fe44f8a758328b551c194a0037538))

### 0.0.26 (2023-10-05)


### Features

* challenge endpoint ([#56](https://github.com/hawks-atlanta/gateway-java/issues/56)) ([613d108](https://github.com/hawks-atlanta/gateway-java/commit/613d1089e4a36e47a4d07377426c687762efaccf))

### 0.0.25 (2023-10-03)

### 0.0.24 (2023-10-03)


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/gateway/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public static void main (String[] args)

// serve SOAP
System.out.println ("Gateway: Starting SOAP");
Endpoint.publish ("http://0.0.0.0:8080/service", new ServiceImp ());
Endpoint.publish ("http://0.0.0.0:8080/gw/service", new ServiceImp ());
}
}
21 changes: 15 additions & 6 deletions app/src/main/java/gateway/controller/CtrlAccountRegister.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gateway.controller;

import gateway.config.Config;
import gateway.services.UtilValidator;
import gateway.soap.request.*;
import gateway.soap.response.*;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
Expand All @@ -17,6 +18,12 @@ public static ResSession account_register (Credentials credentials)
{
ResSession res = new ResSession ();

// validations of all fields
ResStatus resValidate = UtilValidator.validate (credentials);
if (resValidate.error) {
return ResStatus.downCast (ResSession.class, resValidate);
}

String url = Config.getAuthBaseUrl () + "/register";

// Request
Expand All @@ -26,7 +33,6 @@ public static ResSession account_register (Credentials credentials)

try {
// Configs and make HTTP POST request to user register.

HttpResponse<String> response = HttpClient.newHttpClient ().send (
HttpRequest.newBuilder ()
.uri (URI.create (url))
Expand All @@ -41,15 +47,18 @@ public static ResSession account_register (Credentials credentials)

if (res.code == 201) {
res.auth = new Authorization ();
res.error = false;
res.auth.token = jsonObject.getString ("jwt");
res.error = false;
res.msg = "Register succeed";
} else {
res.error = true;
res.msg = jsonObject.getString ("msg");
}

} catch (IOException | InterruptedException e) {
System.err.println (e);
} catch (Exception e) {
e.printStackTrace ();
res.code = 500;
res.error = true;
res.msg = "Internal error, try again later";
}

return res;
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/java/gateway/controller/CtrlAuthLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class CtrlAuthLogin
public static ResSession auth_login (Credentials credentials)
{
// Create a new ResSession object to hold the response data
ResFileNew resFileNew = new ResFileNew ();
ResSession res = new ResSession ();

ResStatus resValidate = UtilValidator.validate (credentials);
Expand Down Expand Up @@ -67,9 +66,9 @@ public static ResSession auth_login (Credentials credentials)
} catch (Exception e) {
// Handle exceptions such as IOException and InterruptedException, if they occur.
System.err.println (e);
resFileNew.code = 500;
resFileNew.error = true;
resFileNew.msg = "Internal error, try again later";
res.code = 500;
res.error = true;
res.msg = "Internal error, try again later";
}

// Return the res object containing the response data.
Expand Down
51 changes: 51 additions & 0 deletions app/src/main/java/gateway/controller/CtrlAuthRefresh.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gateway.controller;

import gateway.config.Config;
import gateway.soap.request.Authorization;
import gateway.soap.response.ResSession;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.json.JSONObject;

public class CtrlAuthRefresh
{

public static ResSession auth_refresh (Authorization authorization)
{
ResSession res = new ResSession ();
String url = Config.getAuthBaseUrl () + "/challenge";

try {

HttpResponse<String> response = HttpClient.newHttpClient ().send (
HttpRequest.newBuilder ()
.uri (URI.create (url))
.POST (HttpRequest.BodyPublishers.noBody ())
.uri (URI.create (url))
.header ("Authorization", "Bearer " + authorization.token)
.build (),
HttpResponse.BodyHandlers.ofString ());

// Response
JSONObject jsonObject = new JSONObject (response.body ());
res.code = response.statusCode ();

if (res.code == 200) {
res.auth = new Authorization ();
res.error = false;
res.auth.token = jsonObject.getString ("jwt");
} else {
res.error = true;
res.msg = jsonObject.getString ("msg");
}

} catch (IOException | InterruptedException e) {
e.printStackTrace ();
}

return res;
}
}
80 changes: 80 additions & 0 deletions app/src/main/java/gateway/controller/CtrlShareFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package gateway.controller;

import gateway.config.Config;
import gateway.services.ServiceAuth;
import gateway.services.ServiceAuth.ResUUID;
import gateway.services.UtilValidator;
import gateway.soap.request.ReqShareFile;
import gateway.soap.response.ResStatus;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.util.UUID;
import org.json.JSONObject;

public class CtrlShareFile
{
public static ResStatus share_file (ReqShareFile args)
{
ResStatus statusRes = new ResStatus ();

// validations of all fields
ResStatus resValidate = UtilValidator.validate (args);
if (resValidate.error) {
return ResStatus.downCast (ResStatus.class, resValidate);
}

// validation of auth
ResStatus resAuth = ServiceAuth.authenticate (args.token);
if (resAuth.error) {
return ResStatus.downCast (ResStatus.class, resAuth);
}

// obtain uuid from user and otheruser
UUID userUUID = UUID.fromString (ServiceAuth.tokenGetClaim (args.token, "uuid"));
ResUUID otherUserUUID = ServiceAuth.getUserUUID (args.token, args.otherUsername);
if (otherUserUUID.error) {
return ResStatus.downCast (ResStatus.class, otherUserUUID);
}

// request to share file with otheruser
JSONObject requestBody = new JSONObject ();
requestBody.put ("otherUserUUID", otherUserUUID.uuid);

String url =
Config.getMetadataBaseUrl () + "/files/share/" + userUUID + "/" + args.fileUUID;

try {

HttpClient client = HttpClient.newHttpClient ();
HttpRequest request = HttpRequest.newBuilder ()
.uri (URI.create (url))
.POST (BodyPublishers.ofString (requestBody.toString ()))
.header ("Content-Type", "application/json")
.build ();

// Response
HttpResponse<String> response =
client.send (request, HttpResponse.BodyHandlers.ofString ());
statusRes.code = response.statusCode ();

if (statusRes.code == 204) {
statusRes.error = false;
statusRes.msg = "The file have been shared";
} else {
JSONObject responseBody = new JSONObject (response.body ());
statusRes.error = true;
statusRes.msg = responseBody.getString ("message");
}
} catch (Exception e) {
e.printStackTrace ();
statusRes.code = 500;
statusRes.error = true;
statusRes.msg = "Internal error, try again later";
}

return statusRes;
}
}
10 changes: 8 additions & 2 deletions app/src/main/java/gateway/soap/ServiceImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
return CtrlAuthLogin.auth_login (credentials);
}

@WebMethod public ResSession auth_refresh (Authorization auth) { return null; }
@WebMethod public ResSession auth_refresh (Authorization auth)
{
return CtrlAuthRefresh.auth_refresh (auth);
}

// account

Expand Down Expand Up @@ -53,7 +56,10 @@

// sharing

@WebMethod public ResStatus share_file (ReqShareFile args) { return null; }
@WebMethod public ResStatus share_file (ReqShareFile args)
{
return CtrlShareFile.share_file (args);
}

@WebMethod public ResStatus unshare_file (ReqShareRemove args) { return null; }

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/gateway/soap/request/Authorization.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public class Authorization
{
public String token;
public Authorization () {}
public Authorization (String token) { this.token = token; }
}
5 changes: 3 additions & 2 deletions app/src/main/java/gateway/soap/request/ReqShareFile.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gateway.soap.request;

import jakarta.validation.constraints.NotNull;
import java.util.UUID;

public class ReqShareFile extends Authorization
{
public UUID fileUUID;
public String otherUsername;
@NotNull public UUID fileUUID;
@NotNull public String otherUsername;
}
50 changes: 49 additions & 1 deletion app/src/test/java/gateway/ITServiceAuth.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import gateway.config.Config;
import gateway.controller.CtrlAccountRegister;
import gateway.controller.CtrlAuthLogin;
import gateway.controller.CtrlAuthRefresh;
import gateway.services.ServiceAuth;
import gateway.soap.request.Authorization;
import gateway.soap.request.Credentials;
import gateway.soap.response.ResSession;
import gateway.testutils.TestUtilConfig;
Expand All @@ -17,6 +19,31 @@ class ITServiceAuth
{
@BeforeEach void setup () { Config.initializeFromEnv (); }

@Test void Register ()
{

Credentials credentials = new Credentials (UUID.randomUUID ().toString (), "pass");

// 201
ResSession res = CtrlAccountRegister.account_register (credentials);
assertEquals (201, res.code, "Register successfully");

// 500 - user already exists
res = CtrlAccountRegister.account_register (credentials);
assertEquals (500, res.code, "Internal server error");

// 500 - without some fields
credentials.username = null;
res = CtrlAccountRegister.account_register (credentials);
assertEquals (400, res.code, "Field: must not be null");

// 500 - all fails
TestUtilConfig.makeInvalidAll ();
credentials.username = UUID.randomUUID ().toString ();
res = CtrlAccountRegister.account_register (credentials);
assertEquals (500, res.code, "Internal error");
}

@Test void Authenticate ()
{
// 200
Expand Down Expand Up @@ -79,4 +106,25 @@ class ITServiceAuth
login = CtrlAuthLogin.auth_login (cred);
assertEquals (500, login.code, "Internal error, try again later");
}
}

@Test void challenge ()
{
// User register

Credentials cred = new Credentials (UUID.randomUUID ().toString (), "pass");

ResSession res = CtrlAccountRegister.account_register (cred);
assertEquals (201, res.code, "Register successfully");

// Challenge validation

Authorization authorization = res.auth;

ResSession challenge = CtrlAuthRefresh.auth_refresh (authorization);
assertEquals (200, challenge.code, "JWT refresh succesfully");

res.auth.token = res.auth.token + "unauthorized";
challenge = CtrlAuthRefresh.auth_refresh (authorization);
assertEquals (401, challenge.code, "Unauthorized");
}
}
Loading

0 comments on commit 405ec70

Please sign in to comment.