From c00598af0c5c6f58150613d06a1693805dee35db Mon Sep 17 00:00:00 2001 From: dzikoysk Date: Sun, 19 Jul 2020 23:01:06 +0200 Subject: [PATCH] GH-164 Fix LookupControllerTest and release 2.7.1 (Resolve #165) --- docs/docs/docker.html | 4 ++-- docs/docs/docker/index.html | 4 ++-- pom.xml | 2 +- reposilite-backend/pom.xml | 2 +- .../panda_lang/reposilite/ReposiliteConstants.java | 2 +- .../panda_lang/reposilite/auth/Authenticator.java | 14 ++++++++------ .../reposilite/repository/IndexApiController.java | 3 ++- .../reposilite/repository/LookupService.java | 4 ++-- .../repository/LookupControllerTest.java | 4 ++-- reposilite-site/docs/docker.md | 4 ++-- 10 files changed, 23 insertions(+), 20 deletions(-) diff --git a/docs/docs/docker.html b/docs/docs/docker.html index 297a12113..2ea6c45e0 100644 --- a/docs/docs/docker.html +++ b/docs/docs/docker.html @@ -61,8 +61,8 @@

Installation

First of all, you have to pull the image from DockerHub:

-
// released builds, e.g. 2.7.0
-$ docker pull dzikoysk/reposilite:2.7.0
+
// released builds, e.g. 2.7.1
+$ docker pull dzikoysk/reposilite:2.7.1
 
 // nightly builds
 $ docker pull dzikoysk/reposilite:nightly
diff --git a/docs/docs/docker/index.html b/docs/docs/docker/index.html
index 297a12113..2ea6c45e0 100644
--- a/docs/docs/docker/index.html
+++ b/docs/docs/docker/index.html
@@ -61,8 +61,8 @@
 
 

Installation

First of all, you have to pull the image from DockerHub:

-
// released builds, e.g. 2.7.0
-$ docker pull dzikoysk/reposilite:2.7.0
+
// released builds, e.g. 2.7.1
+$ docker pull dzikoysk/reposilite:2.7.1
 
 // nightly builds
 $ docker pull dzikoysk/reposilite:nightly
diff --git a/pom.xml b/pom.xml
index c1cf76ca5..b42005102 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
     org.panda-lang
     reposilite-parent
     pom
-    2.7.0
+    2.7.1
 
     
         reposilite-backend
diff --git a/reposilite-backend/pom.xml b/reposilite-backend/pom.xml
index b8dafebeb..853f923c3 100644
--- a/reposilite-backend/pom.xml
+++ b/reposilite-backend/pom.xml
@@ -18,7 +18,7 @@
     
         reposilite-parent
         org.panda-lang
-        2.7.0
+        2.7.1
     
     4.0.0
 
diff --git a/reposilite-backend/src/main/java/org/panda_lang/reposilite/ReposiliteConstants.java b/reposilite-backend/src/main/java/org/panda_lang/reposilite/ReposiliteConstants.java
index 15b33ba1b..1dc17facc 100644
--- a/reposilite-backend/src/main/java/org/panda_lang/reposilite/ReposiliteConstants.java
+++ b/reposilite-backend/src/main/java/org/panda_lang/reposilite/ReposiliteConstants.java
@@ -18,7 +18,7 @@
 
 public final class ReposiliteConstants {
 
-    public static final String VERSION = "2.7.0";
+    public static final String VERSION = "2.7.1";
 
     public static final String REMOTE_VERSION = "https://repo.panda-lang.org/org/panda-lang/reposilite/latest";
 
diff --git a/reposilite-backend/src/main/java/org/panda_lang/reposilite/auth/Authenticator.java b/reposilite-backend/src/main/java/org/panda_lang/reposilite/auth/Authenticator.java
index c7530916d..a1260d320 100644
--- a/reposilite-backend/src/main/java/org/panda_lang/reposilite/auth/Authenticator.java
+++ b/reposilite-backend/src/main/java/org/panda_lang/reposilite/auth/Authenticator.java
@@ -17,8 +17,10 @@
 package org.panda_lang.reposilite.auth;
 
 import io.javalin.http.Context;
+import org.apache.http.HttpStatus;
 import org.jetbrains.annotations.Nullable;
 import org.panda_lang.reposilite.Reposilite;
+import org.panda_lang.reposilite.api.ErrorDto;
 import org.panda_lang.reposilite.config.Configuration;
 import org.panda_lang.reposilite.repository.Repository;
 import org.panda_lang.reposilite.repository.RepositoryService;
@@ -43,28 +45,28 @@ public Authenticator(Configuration configuration, RepositoryService repositorySe
         this.tokenService = tokenService;
     }
 
-    public Result, String> authDefaultRepository(Context context, String uri) {
+    public Result, ErrorDto> authDefaultRepository(Context context, String uri) {
         return authRepository(context, RepositoryUtils.normalizeUri(configuration, repositoryService, uri));
     }
 
-    public Result, String> authRepository(Context context, String uri) {
+    public Result, ErrorDto> authRepository(Context context, String uri) {
         String[] path = StringUtils.split(uri, "/");
 
         // discard invalid requests (less than 'repository/group/artifact')
         if (path.length < 1) {
-            return Result.error("Unsupported request");
+            return Result.error(new ErrorDto(HttpStatus.SC_OK, "Unsupported request"));
         }
 
         String repositoryName = path[0];
 
         if (StringUtils.isEmpty(repositoryName)) {
-            return Result.error("Unsupported request");
+            return Result.error(new ErrorDto(HttpStatus.SC_OK, "Unsupported request"));
         }
 
         Repository repository = repositoryService.getRepository(path[0]);
 
         if (repository == null) {
-            return Result.error("Repository " + path[0] + " not found");
+            return Result.error(new ErrorDto(HttpStatus.SC_OK, "Repository " + path[0] + " not found"));
         }
 
         // auth hidden repositories
@@ -72,7 +74,7 @@ public Result, String> authRepository(Context context
             Result authResult = authDefault(context);
 
             if (authResult.containsError()) {
-                return Result.error("Unauthorized request");
+                return Result.error(new ErrorDto(HttpStatus.SC_UNAUTHORIZED, "Unauthorized request"));
             }
         }
 
diff --git a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/IndexApiController.java b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/IndexApiController.java
index fac59ff8a..3399caeed 100644
--- a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/IndexApiController.java
+++ b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/IndexApiController.java
@@ -21,6 +21,7 @@
 import org.apache.http.HttpStatus;
 import org.panda_lang.reposilite.Reposilite;
 import org.panda_lang.reposilite.RepositoryController;
+import org.panda_lang.reposilite.api.ErrorDto;
 import org.panda_lang.reposilite.api.ErrorUtils;
 import org.panda_lang.reposilite.auth.Authenticator;
 import org.panda_lang.reposilite.config.Configuration;
@@ -56,7 +57,7 @@ public Context handleContext(Context context) {
             return context.json(listRepositories(context));
         }
 
-        Result, String> result = authenticator.authRepository(context, uri);
+        Result, ErrorDto> result = authenticator.authRepository(context, uri);
 
         if (result.containsError()) {
             return ErrorUtils.error(context, HttpStatus.SC_UNAUTHORIZED, "Unauthorized request");
diff --git a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupService.java b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupService.java
index 12446b018..389f427d5 100644
--- a/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupService.java
+++ b/reposilite-backend/src/main/java/org/panda_lang/reposilite/repository/LookupService.java
@@ -72,10 +72,10 @@ public LookupService(Reposilite reposilite) {
     }
 
     protected Result serveLocal(Context context) {
-        Result, String> result = this.authenticator.authDefaultRepository(context, context.req.getRequestURI());
+        Result, ErrorDto> result = this.authenticator.authDefaultRepository(context, context.req.getRequestURI());
 
         if (result.containsError()) {
-            return Result.error(new ErrorDto(HttpStatus.SC_UNAUTHORIZED, result.getError()));
+            return Result.error(result.getError());
         }
 
         String[] path = result.getValue().getKey();
diff --git a/reposilite-backend/src/test/java/org/panda_lang/reposilite/repository/LookupControllerTest.java b/reposilite-backend/src/test/java/org/panda_lang/reposilite/repository/LookupControllerTest.java
index 98cbd87cb..7f1f94339 100644
--- a/reposilite-backend/src/test/java/org/panda_lang/reposilite/repository/LookupControllerTest.java
+++ b/reposilite-backend/src/test/java/org/panda_lang/reposilite/repository/LookupControllerTest.java
@@ -118,8 +118,8 @@ void shouldReturn200AndHeadRequestedFile() throws IOException {
     }
 
     @Test
-    void shouldReturn200WithUnauthorizedMessage() throws IOException {
-        assertResponseWithMessage(super.get("/private/a/b"), HttpStatus.SC_OK, "Unauthorized request");
+    void shouldReturn401WithUnauthorizedMessage() throws IOException {
+        assertResponseWithMessage(super.get("/private/a/b"), HttpStatus.SC_UNAUTHORIZED, "Unauthorized request");
     }
 
     @Test
diff --git a/reposilite-site/docs/docker.md b/reposilite-site/docs/docker.md
index 56fb21871..0b8c8c6be 100644
--- a/reposilite-site/docs/docker.md
+++ b/reposilite-site/docs/docker.md
@@ -13,8 +13,8 @@ Reposilite defines two types of builds:
 First of all, you have to pull the image from [DockerHub](https://hub.docker.com/r/dzikoysk/reposilite):
 
 ```shell-session
-// released builds, e.g. 2.7.0
-$ docker pull dzikoysk/reposilite:2.7.0
+// released builds, e.g. 2.7.1
+$ docker pull dzikoysk/reposilite:2.7.1
 
 // nightly builds
 $ docker pull dzikoysk/reposilite:nightly