forked from cloudreve/Cloudreve
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: move slave pkg inside of cluster
Test: middleware for node communication
- Loading branch information
Showing
16 changed files
with
135 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ func SignRequired(authInstance auth.Auth) gin.HandlerFunc { | |
c.Abort() | ||
return | ||
} | ||
|
||
c.Next() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package middleware | ||
|
||
import ( | ||
model "github.com/cloudreve/Cloudreve/v3/models" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/auth" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/cluster" | ||
"github.com/gin-gonic/gin" | ||
"github.com/jinzhu/gorm" | ||
"github.com/stretchr/testify/assert" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestMasterMetadata(t *testing.T) { | ||
a := assert.New(t) | ||
masterMetaDataFunc := MasterMetadata() | ||
rec := httptest.NewRecorder() | ||
c, _ := gin.CreateTestContext(rec) | ||
c.Request = httptest.NewRequest("GET", "/", nil) | ||
|
||
c.Request.Header = map[string][]string{ | ||
"X-Site-Id": {"expectedSiteID"}, | ||
"X-Site-Url": {"expectedSiteURL"}, | ||
"X-Cloudreve-Version": {"expectedMasterVersion"}, | ||
} | ||
masterMetaDataFunc(c) | ||
siteID, _ := c.Get("MasterSiteID") | ||
siteURL, _ := c.Get("MasterSiteURL") | ||
siteVersion, _ := c.Get("MasterVersion") | ||
|
||
a.Equal("expectedSiteID", siteID.(string)) | ||
a.Equal("expectedSiteURL", siteURL.(string)) | ||
a.Equal("expectedMasterVersion", siteVersion.(string)) | ||
} | ||
|
||
func TestSlaveRPCSignRequired(t *testing.T) { | ||
a := assert.New(t) | ||
np := &cluster.NodePool{} | ||
np.Init() | ||
slaveRPCSignRequiredFunc := SlaveRPCSignRequired(np) | ||
rec := httptest.NewRecorder() | ||
|
||
// id parse failed | ||
{ | ||
c, _ := gin.CreateTestContext(rec) | ||
c.Request = httptest.NewRequest("GET", "/", nil) | ||
c.Request.Header.Set("X-Node-Id", "unknown") | ||
slaveRPCSignRequiredFunc(c) | ||
a.True(c.IsAborted()) | ||
} | ||
|
||
// node id not exist | ||
{ | ||
c, _ := gin.CreateTestContext(rec) | ||
c.Request = httptest.NewRequest("GET", "/", nil) | ||
c.Request.Header.Set("X-Node-Id", "38") | ||
slaveRPCSignRequiredFunc(c) | ||
a.True(c.IsAborted()) | ||
} | ||
|
||
// success | ||
{ | ||
authInstance := auth.HMACAuth{SecretKey: []byte("")} | ||
np.Add(&model.Node{Model: gorm.Model{ | ||
ID: 38, | ||
}}) | ||
|
||
c, _ := gin.CreateTestContext(rec) | ||
c.Request = httptest.NewRequest("POST", "/", nil) | ||
c.Request.Header.Set("X-Node-Id", "38") | ||
c.Request = auth.SignRequest(authInstance, c.Request, 0) | ||
slaveRPCSignRequiredFunc(c) | ||
a.False(c.IsAborted()) | ||
} | ||
} | ||
|
||
func TestUseSlaveAria2Instance(t *testing.T) { | ||
a := assert.New(t) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package cluster | ||
|
||
import "errors" | ||
import ( | ||
"errors" | ||
"github.com/cloudreve/Cloudreve/v3/pkg/serializer" | ||
) | ||
|
||
var ( | ||
ErrFeatureNotExist = errors.New("No nodes in nodepool match the feature specificed") | ||
ErrIlegalPath = errors.New("path out of boundary of setting temp folder") | ||
ErrMasterNotFound = serializer.NewError(serializer.CodeMasterNotFound, "未知的主机节点", nil) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.