Skip to content

Commit

Permalink
Fix: fix linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Jan 17, 2024
1 parent 2216604 commit 03c992c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
3 changes: 2 additions & 1 deletion internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ func Init() {
}

type NFContext interface {
var _ NFContext = &NSSFContext{}
AuthorizationCheck(token, serviceName string) error
}

var _ NFContext = &NSSFContext{}

type NSSFContext struct {
NfId string
Name string
Expand Down
3 changes: 2 additions & 1 deletion internal/sbi/consumer/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ package consumer

import (
"fmt"
"github.com/pkg/errors"
"net/http"
"strings"
"time"

"github.com/pkg/errors"

nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/openapi"
Expand Down
4 changes: 2 additions & 2 deletions internal/sbi/nssaiavailability/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
package nssaiavailability

import (
nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/util"
"net/http"
"strings"

"github.com/gin-gonic/gin"

nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/util"
"github.com/free5gc/nssf/pkg/factory"
logger_util "github.com/free5gc/util/logger"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/sbi/nsselection/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
package nsselection

import (
nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/util"
"net/http"
"strings"

"github.com/gin-gonic/gin"

nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/logger"
"github.com/free5gc/nssf/internal/util"
"github.com/free5gc/nssf/pkg/factory"
logger_util "github.com/free5gc/util/logger"
)
Expand Down
7 changes: 4 additions & 3 deletions internal/util/router_auth_check.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package util

import (
"net/http"

"github.com/gin-gonic/gin"

nssf_context "github.com/free5gc/nssf/internal/context"
"github.com/free5gc/nssf/internal/logger"
"github.com/gin-gonic/gin"
"net/http"
)

type RouterAuthorizationCheck struct {
Expand All @@ -20,7 +22,6 @@ func NewRouterAuthorizationCheck(serviceName string) *RouterAuthorizationCheck {
func (rac *RouterAuthorizationCheck) Check(c *gin.Context, nssfContext nssf_context.NFContext) {
token := c.Request.Header.Get("Authorization")
err := nssfContext.AuthorizationCheck(token, rac.serviceName)

if err != nil {
logger.UtilLog.Debugf("RouterAuthorizationCheck: Check Unauthorized: %s", err)
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
Expand Down
17 changes: 13 additions & 4 deletions internal/util/router_auth_check_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package util

import (
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"net/http"
"net/http/httptest"
"testing"

"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)

const (
Expand All @@ -31,7 +32,12 @@ func TestRouterAuthorizationCheck_Check(t *testing.T) {
// Mock gin.Context
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request, _ = http.NewRequest("GET", "/", nil)

var err error
c.Request, err = http.NewRequest("GET", "/", nil)
if err != nil {
t.Errorf("error on http request: %+v", err)
}

type Args struct {
token string
Expand Down Expand Up @@ -69,7 +75,10 @@ func TestRouterAuthorizationCheck_Check(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
w = httptest.NewRecorder()
c, _ = gin.CreateTestContext(w)
c.Request, _ = http.NewRequest("GET", "/", nil)
c.Request, err = http.NewRequest("GET", "/", nil)
if err != nil {
t.Errorf("error on http request: %+v", err)
}
c.Request.Header.Set("Authorization", tt.args.token)

rac := NewRouterAuthorizationCheck("testService")
Expand Down

0 comments on commit 03c992c

Please sign in to comment.