From 47566e65b5040ea7935717a14e96af49dd37a93f Mon Sep 17 00:00:00 2001
From: ko_oler <kooler89@gmail.com>
Date: Thu, 5 Oct 2023 11:16:36 +0300
Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?=
 =?UTF-8?q?=D0=BE=20=D0=9F=D0=A0:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?=
 =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?=
 =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0?=
 =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20extension=20ID,=20=D0=BF=D0=BE=D0=BF?=
 =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81?=
 =?UTF-8?q?=D1=82=D1=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pkg/action/action_test.go          | 85 ++++--------------------------
 pkg/extension/server.go            |  5 +-
 pkg/extension/server_test.go       | 10 ++++
 pkg/extension/service/extension.go |  5 +-
 4 files changed, 29 insertions(+), 76 deletions(-)

diff --git a/pkg/action/action_test.go b/pkg/action/action_test.go
index 07833440..2988744f 100644
--- a/pkg/action/action_test.go
+++ b/pkg/action/action_test.go
@@ -19,19 +19,7 @@ func TestActionURL_New(t *testing.T) {
 		{
 			name: "Without action",
 			want: &URL{
-				URL: &url.URL{
-					Scheme:      "",
-					Opaque:      "",
-					User:        nil,
-					Host:        "",
-					Path:        "",
-					RawPath:     "",
-					OmitHost:    false,
-					ForceQuery:  false,
-					RawQuery:    "",
-					Fragment:    "",
-					RawFragment: "",
-				},
+				URL: &url.URL{},
 			},
 			wantErr: assert.NoError,
 		},
@@ -40,17 +28,7 @@ func TestActionURL_New(t *testing.T) {
 			action: "build-site",
 			want: &URL{
 				URL: &url.URL{
-					Scheme:      "",
-					Opaque:      "",
-					User:        nil,
-					Host:        "",
-					Path:        "build-site",
-					RawPath:     "",
-					OmitHost:    false,
-					ForceQuery:  false,
-					RawQuery:    "",
-					Fragment:    "",
-					RawFragment: "",
+					Path: "build-site",
 				},
 			},
 			url:     "build-site",
@@ -61,17 +39,8 @@ func TestActionURL_New(t *testing.T) {
 			action: "grpc:///perxisweb/build-site",
 			want: &URL{
 				URL: &url.URL{
-					Scheme:      "grpc",
-					Opaque:      "",
-					User:        nil,
-					Host:        "",
-					Path:        "/perxisweb/build-site",
-					RawPath:     "",
-					OmitHost:    false,
-					ForceQuery:  false,
-					RawQuery:    "",
-					Fragment:    "",
-					RawFragment: "",
+					Scheme: "grpc",
+					Path:   "/perxisweb/build-site",
 				},
 			},
 			url:     "grpc:///perxisweb/build-site",
@@ -82,17 +51,8 @@ func TestActionURL_New(t *testing.T) {
 			action: "ui:///space/env/coll",
 			want: &URL{
 				URL: &url.URL{
-					Scheme:      "ui",
-					Opaque:      "",
-					User:        nil,
-					Host:        "",
-					Path:        "/space/env/coll",
-					RawPath:     "",
-					OmitHost:    false,
-					ForceQuery:  false,
-					RawQuery:    "",
-					Fragment:    "",
-					RawFragment: "",
+					Scheme: "ui",
+					Path:   "/space/env/coll",
 				},
 			},
 			url:     "ui:///space/env/coll",
@@ -103,17 +63,8 @@ func TestActionURL_New(t *testing.T) {
 			action: "https://perx.ru",
 			want: &URL{
 				URL: &url.URL{
-					Scheme:      "https",
-					Opaque:      "",
-					User:        nil,
-					Host:        "perx.ru",
-					Path:        "",
-					RawPath:     "",
-					OmitHost:    false,
-					ForceQuery:  false,
-					RawQuery:    "",
-					Fragment:    "",
-					RawFragment: "",
+					Scheme: "https",
+					Host:   "perx.ru",
 				},
 			},
 			url:     "https://perx.ru",
@@ -130,17 +81,8 @@ func TestActionURL_New(t *testing.T) {
 			action: "grpc:///perxisweb",
 			want: &URL{
 				URL: &url.URL{
-					Scheme:      "grpc",
-					Opaque:      "",
-					User:        nil,
-					Host:        "",
-					Path:        "/perxisweb",
-					RawPath:     "",
-					OmitHost:    false,
-					ForceQuery:  false,
-					RawQuery:    "",
-					Fragment:    "",
-					RawFragment: "",
+					Scheme: "grpc",
+					Path:   "/perxisweb",
 				},
 			},
 			wantErr: assert.NoError,
@@ -166,33 +108,28 @@ func TestActionURL_String(t *testing.T) {
 		{
 			name: "GRPC action",
 			url:  "grpc:///perxisweb/build-site",
-			want: "grpc:///perxisweb/build-site",
 		},
 		{
 			name: "UI action #1",
 			url:  "ui:///space/env/coll",
-			want: "ui:///space/env/coll",
 		},
 		{
 			name: "UI action deprecated call #2",
 			url:  "space/env/coll",
-			want: "space/env/coll",
 		},
 		{
 			name: "Https action",
 			url:  "https://perx.ru",
-			want: "https://perx.ru",
 		},
 		{
 			name: "With action deprecated call",
 			url:  "extension-id",
-			want: "extension-id",
 		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			p, _ := NewURL(tt.url)
-			assert.Equalf(t, tt.want, p.String(), "String()")
+			assert.Equalf(t, tt.url, p.String(), "String()")
 		})
 	}
 }
diff --git a/pkg/extension/server.go b/pkg/extension/server.go
index 6f2c2442..f9b603f5 100644
--- a/pkg/extension/server.go
+++ b/pkg/extension/server.go
@@ -86,9 +86,12 @@ func (srv *Server) Action(ctx context.Context, in *pb.ActionRequest) (*pb.Action
 		return nil, err
 	}
 	ext := actionURL.Extension()
-	if ext == "" && in.Extension != "" {
+	if ext == "" {
 		ext = in.Extension
 	}
+	if ext == "" {
+		return nil, errors.New("extension ID required")
+	}
 
 	svc, ok := srv.services[ext]
 	if !ok {
diff --git a/pkg/extension/server_test.go b/pkg/extension/server_test.go
index 9e8b8f4c..3f8e408b 100644
--- a/pkg/extension/server_test.go
+++ b/pkg/extension/server_test.go
@@ -168,6 +168,16 @@ func TestServer_Action(t *testing.T) {
 			want:    nil,
 			wantErr: assert.Error,
 		},
+		{
+			name:     "Error (deprecated call, no action and extension)",
+			services: map[string]Extension{"test-extension": getDummyExtension("test-extension")},
+			in: &ActionRequest{
+				SpaceId: "sp",
+				EnvId:   "env",
+			},
+			want:    nil,
+			wantErr: assert.Error,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
diff --git a/pkg/extension/service/extension.go b/pkg/extension/service/extension.go
index 8b9aefd3..6d9608ab 100644
--- a/pkg/extension/service/extension.go
+++ b/pkg/extension/service/extension.go
@@ -161,9 +161,12 @@ func (s *Extension) Action(ctx context.Context, in *extension.ActionRequest) (*e
 		return nil, err
 	}
 	ext := actionURL.Extension()
-	if ext == "" && in.Extension != "" {
+	if ext == "" {
 		ext = in.Extension
 	}
+	if ext == "" {
+		return nil, errors.New("extension ID required")
+	}
 	ok, err := extension.CheckInstalled(ctx, s.Content, in.SpaceId, in.EnvId, ext)
 	if err != nil {
 		return nil, errors.Wrap(err, "check extension installed")
-- 
GitLab