Skip to content

Commit

Permalink
Words typo in codes fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
yukimochi committed Jun 20, 2021
1 parent 4dd69d0 commit f059214
Show file tree
Hide file tree
Showing 20 changed files with 85 additions and 85 deletions.
10 changes: 5 additions & 5 deletions api/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func decodeActivity(request *http.Request) (*models.Activity, *models.Actor, []b
}
KeyID := verifier.KeyId()
keyOwnerActor := new(models.Actor)
err = keyOwnerActor.RetrieveRemoteActor(KeyID, fmt.Sprintf("%s (golang net/http; Activity-Relay %s; %s)", globalConfig.ServerServicename(), version, globalConfig.ServerHostname().Host), actorCache)
err = keyOwnerActor.RetrieveRemoteActor(KeyID, fmt.Sprintf("%s (golang net/http; Activity-Relay %s; %s)", globalConfig.ServerServiceName(), version, globalConfig.ServerHostname().Host), actorCache)
if err != nil {
return nil, nil, nil, err
}
PubKey, err := models.ReadPublicKeyRSAfromString(keyOwnerActor.PublicKey.PublicKeyPem)
PubKey, err := models.ReadPublicKeyRSAFromString(keyOwnerActor.PublicKey.PublicKeyPem)
if PubKey == nil {
return nil, nil, nil, errors.New("Failed parse PublicKey from string")
}
Expand All @@ -47,9 +47,9 @@ func decodeActivity(request *http.Request) (*models.Activity, *models.Actor, []b
hash := sha256.New()
hash.Write(body)
b := hash.Sum(nil)
calcurateDigest := "SHA-256=" + base64.StdEncoding.EncodeToString(b)
calculatedDigest := "SHA-256=" + base64.StdEncoding.EncodeToString(b)

if givenDigest != calcurateDigest {
if givenDigest != calculatedDigest {
return nil, nil, nil, errors.New("Digest header is mismatch")
}

Expand All @@ -61,7 +61,7 @@ func decodeActivity(request *http.Request) (*models.Activity, *models.Actor, []b
}

var remoteActor models.Actor
err = remoteActor.RetrieveRemoteActor(activity.Actor, fmt.Sprintf("%s (golang net/http; Activity-Relay %s; %s)", globalConfig.ServerServicename(), version, globalConfig.ServerHostname().Host), actorCache)
err = remoteActor.RetrieveRemoteActor(activity.Actor, fmt.Sprintf("%s (golang net/http; Activity-Relay %s; %s)", globalConfig.ServerServiceName(), version, globalConfig.ServerHostname().Host), actorCache)
if err != nil {
return nil, nil, nil, err
}
Expand Down
26 changes: 13 additions & 13 deletions api/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ func handleWebfinger(writer http.ResponseWriter, request *http.Request) {
} else {
request := resource[0]
if request == WebfingerResource.Subject {
wfresource, err := json.Marshal(&WebfingerResource)
webfingerResource, err := json.Marshal(&WebfingerResource)
if err != nil {
panic(err)
}
writer.Header().Add("Content-Type", "application/json")
writer.WriteHeader(200)
writer.Write(wfresource)
writer.Write(webfingerResource)
} else {
writer.WriteHeader(404)
writer.Write(nil)
Expand All @@ -39,13 +39,13 @@ func handleNodeinfoLink(writer http.ResponseWriter, request *http.Request) {
writer.WriteHeader(400)
writer.Write(nil)
} else {
linksresource, err := json.Marshal(&Nodeinfo.NodeinfoLinks)
linksResource, err := json.Marshal(&Nodeinfo.NodeinfoLinks)
if err != nil {
panic(err)
}
writer.Header().Add("Content-Type", "application/json")
writer.WriteHeader(200)
writer.Write(linksresource)
writer.Write(linksResource)
}
}

Expand All @@ -58,13 +58,13 @@ func handleNodeinfo(writer http.ResponseWriter, request *http.Request) {
Nodeinfo.Nodeinfo.Usage.Users.Total = userCount
Nodeinfo.Nodeinfo.Usage.Users.ActiveMonth = userCount
Nodeinfo.Nodeinfo.Usage.Users.ActiveHalfyear = userCount
linksresource, err := json.Marshal(&Nodeinfo.Nodeinfo)
linksResource, err := json.Marshal(&Nodeinfo.Nodeinfo)
if err != nil {
panic(err)
}
writer.Header().Add("Content-Type", "application/json")
writer.WriteHeader(200)
writer.Write(linksresource)
writer.Write(linksResource)
}
}

Expand Down Expand Up @@ -132,9 +132,9 @@ func pushRelayJob(sourceInbox string, body []byte) {
}
}

func pushRegistorJob(inboxURL string, body []byte) {
func pushRegisterJob(inboxURL string, body []byte) {
job := &tasks.Signature{
Name: "registor",
Name: "register",
RetryCount: 2,
Args: []tasks.Arg{
{
Expand Down Expand Up @@ -181,13 +181,13 @@ func suitableFollow(activity *models.Activity, actor *models.Actor) bool {

func relayAcceptable(activity *models.Activity, actor *models.Actor) error {
if !contains(activity.To, "https://www.w3.org/ns/activitystreams#Public") && !contains(activity.Cc, "https://www.w3.org/ns/activitystreams#Public") {
return errors.New("Activity should contain https://www.w3.org/ns/activitystreams#Public as receiver")
return errors.New("activity should contain https://www.w3.org/ns/activitystreams#Public as receiver")
}
domain, _ := url.Parse(activity.Actor)
if contains(relayState.Subscriptions, domain.Host) {
return nil
}
return errors.New("To use the relay service, Subscribe me in advance")
return errors.New("to use the relay service, Subscribe me in advance")
}

func suitableRelay(activity *models.Activity, actor *models.Actor) bool {
Expand Down Expand Up @@ -216,7 +216,7 @@ func handleInbox(writer http.ResponseWriter, request *http.Request, activityDeco
if err != nil {
resp := activity.GenerateResponse(globalConfig.ServerHostname(), "Reject")
jsonData, _ := json.Marshal(&resp)
go pushRegistorJob(actor.Inbox, jsonData)
go pushRegisterJob(actor.Inbox, jsonData)
fmt.Println("Reject Follow Request : ", err.Error(), activity.Actor)

writer.WriteHeader(202)
Expand All @@ -235,7 +235,7 @@ func handleInbox(writer http.ResponseWriter, request *http.Request, activityDeco
} else {
resp := activity.GenerateResponse(globalConfig.ServerHostname(), "Accept")
jsonData, _ := json.Marshal(&resp)
go pushRegistorJob(actor.Inbox, jsonData)
go pushRegisterJob(actor.Inbox, jsonData)
relayState.AddSubscription(models.Subscription{
Domain: domain.Host,
InboxURL: actor.Endpoints.SharedInbox,
Expand All @@ -247,7 +247,7 @@ func handleInbox(writer http.ResponseWriter, request *http.Request, activityDeco
} else {
resp := activity.GenerateResponse(globalConfig.ServerHostname(), "Reject")
jsonData, _ := json.Marshal(&resp)
go pushRegistorJob(actor.Inbox, jsonData)
go pushRegisterJob(actor.Inbox, jsonData)
fmt.Println("Reject Follow Request : ", activity.Actor)
}

Expand Down
12 changes: 6 additions & 6 deletions api/handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func TestHandleWebfingerGet(t *testing.T) {
defer r.Body.Close()

data, _ := ioutil.ReadAll(r.Body)
var wfresource models.WebfingerResource
err = json.Unmarshal(data, &wfresource)
var webfingerResource models.WebfingerResource
err = json.Unmarshal(data, &webfingerResource)
if err != nil {
t.Fatalf("WebfingerResource response is not valid.")
}

domain, _ := url.Parse(wfresource.Links[0].Href)
domain, _ := url.Parse(webfingerResource.Links[0].Href)
if domain.Host != globalConfig.ServerHostname().Host {
t.Fatalf("WebfingerResource's Host not valid.")
}
Expand Down Expand Up @@ -305,7 +305,7 @@ func mockActivity(req string) models.Activity {
json.Unmarshal(body, &activity)
return activity
default:
panic("No assined request.")
panic("No assigned request.")
}
}

Expand All @@ -330,7 +330,7 @@ func mockActor(req string) models.Actor {
json.Unmarshal(body, &actor)
return actor
default:
panic("No assined request.")
panic("No assigned request.")
}
}

Expand Down Expand Up @@ -642,7 +642,7 @@ func TestHandleInboxValidCreate(t *testing.T) {
relayState.RedisClient.Del("relay:subscription:example.org").Result()
}

func TestHandleInboxlimitedCreate(t *testing.T) {
func TestHandleInboxLimitedCreate(t *testing.T) {
activity := mockActivity("Create")
actor := mockActor("Person")
domain, _ := url.Parse(activity.Actor)
Expand Down
14 changes: 7 additions & 7 deletions control/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ func configCmdInit() *cobra.Command {
var config = &cobra.Command{
Use: "config",
Short: "Manage configuration for relay",
Long: "Enable/disable relay costomize and import/export relay database.",
Long: "Enable/disable relay customize and import/export relay database.",
}

var configList = &cobra.Command{
Use: "list",
Short: "List all relay configration",
Long: "List all relay configration.",
Short: "List all relay configuration",
Long: "List all relay configuration.",
Run: func(cmd *cobra.Command, args []string) {
initProxy(listConfig, cmd, args)
},
Expand Down Expand Up @@ -57,8 +57,8 @@ func configCmdInit() *cobra.Command {

var configEnable = &cobra.Command{
Use: "enable",
Short: "Enable/disable relay configration",
Long: `Enable or disable relay configration.
Short: "Enable/disable relay configuration",
Long: `Enable or disable relay configuration.
- service-block
Blocking feature for service-type actor.
- manually-accept
Expand All @@ -70,7 +70,7 @@ func configCmdInit() *cobra.Command {
return initProxyE(configEnable, cmd, args)
},
}
configEnable.Flags().BoolP("disable", "d", false, "Disable configration instead of Enable")
configEnable.Flags().BoolP("disable", "d", false, "Disable configuration instead of Enable")
config.AddCommand(configEnable)

return config
Expand Down Expand Up @@ -168,6 +168,6 @@ func importConfig(cmd *cobra.Command, args []string) {
ActivityID: Subscription.ActivityID,
ActorID: Subscription.ActorID,
})
cmd.Println("Regist [" + Subscription.Domain + "] as subscriber")
cmd.Println("Register [" + Subscription.Domain + "] as subscriber")
}
}
12 changes: 6 additions & 6 deletions control/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestInvalidConfig(t *testing.T) {

app := configCmdInit()
buffer := new(bytes.Buffer)
app.SetOutput(buffer)
app.SetOut(buffer)

app.SetArgs([]string{"enable", "hoge"})
app.Execute()
Expand All @@ -89,7 +89,7 @@ func TestListConfig(t *testing.T) {

app := configCmdInit()
buffer := new(bytes.Buffer)
app.SetOutput(buffer)
app.SetOut(buffer)

app.SetArgs([]string{"list"})
app.Execute()
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestExportConfig(t *testing.T) {

app := configCmdInit()
buffer := new(bytes.Buffer)
app.SetOutput(buffer)
app.SetOut(buffer)

app.SetArgs([]string{"export"})
app.Execute()
Expand All @@ -127,7 +127,7 @@ func TestExportConfig(t *testing.T) {
if err != nil {
t.Fatalf("Test resource fetch error.")
}
jsonData, err := ioutil.ReadAll(file)
jsonData, _ := ioutil.ReadAll(file)
output := buffer.String()
if strings.Split(output, "\n")[0] != string(jsonData) {
t.Fatalf("Invalid Response.")
Expand All @@ -144,7 +144,7 @@ func TestImportConfig(t *testing.T) {
relayState.Load()

buffer := new(bytes.Buffer)
app.SetOutput(buffer)
app.SetOut(buffer)

app.SetArgs([]string{"export"})
app.Execute()
Expand All @@ -153,7 +153,7 @@ func TestImportConfig(t *testing.T) {
if err != nil {
t.Fatalf("Test resource fetch error.")
}
jsonData, err := ioutil.ReadAll(file)
jsonData, _ := ioutil.ReadAll(file)
output := buffer.String()
if strings.Split(output, "\n")[0] != string(jsonData) {
t.Fatalf("Invalid Response.")
Expand Down
2 changes: 1 addition & 1 deletion control/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func createUnfollowRequestResponse(subscription models.Subscription) error {

resp := activity.GenerateResponse(globalConfig.ServerHostname(), "Reject")
jsonData, _ := json.Marshal(&resp)
pushRegistorJob(subscription.InboxURL, jsonData)
pushRegisterJob(subscription.InboxURL, jsonData)

return nil
}
Expand Down
10 changes: 5 additions & 5 deletions control/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestListDomainSubscriber(t *testing.T) {
buffer := new(bytes.Buffer)

app = domainCmdInit()
app.SetOutput(buffer)
app.SetOut(buffer)
app.SetArgs([]string{"list"})
app.Execute()

Expand All @@ -43,7 +43,7 @@ func TestListDomainLimited(t *testing.T) {
buffer := new(bytes.Buffer)

app = domainCmdInit()
app.SetOutput(buffer)
app.SetOut(buffer)
app.SetArgs([]string{"list", "-t", "limited"})
app.Execute()

Expand All @@ -69,7 +69,7 @@ func TestListDomainBlocked(t *testing.T) {
buffer := new(bytes.Buffer)

app = domainCmdInit()
app.SetOutput(buffer)
app.SetOut(buffer)
app.SetArgs([]string{"list", "-t", "blocked"})
app.Execute()

Expand Down Expand Up @@ -187,7 +187,7 @@ func TestSetDomainInvalid(t *testing.T) {
buffer := new(bytes.Buffer)

app = domainCmdInit()
app.SetOutput(buffer)
app.SetOut(buffer)
app.SetArgs([]string{"set", "-t", "hoge", "hoge.example.jp"})
app.Execute()

Expand Down Expand Up @@ -234,7 +234,7 @@ func TestInvalidUnfollowDomain(t *testing.T) {
buffer := new(bytes.Buffer)

app = domainCmdInit()
app.SetOutput(buffer)
app.SetOut(buffer)
app.SetArgs([]string{"unfollow", "unknown.tld"})
app.Execute()

Expand Down
8 changes: 4 additions & 4 deletions control/follow.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func followCmdInit() *cobra.Command {
return follow
}

func pushRegistorJob(inboxURL string, body []byte) {
func pushRegisterJob(inboxURL string, body []byte) {
job := &tasks.Signature{
Name: "registor",
Name: "register",
RetryCount: 25,
Args: []tasks.Arg{
{
Expand Down Expand Up @@ -105,7 +105,7 @@ func createFollowRequestResponse(domain string, response string) error {
if err != nil {
return err
}
pushRegistorJob(data["inbox_url"], jsonData)
pushRegisterJob(data["inbox_url"], jsonData)
relayState.RedisClient.Del("relay:pending:" + domain)
if response == "Accept" {
relayState.AddSubscription(models.Subscription{
Expand Down Expand Up @@ -133,7 +133,7 @@ func createUpdateActorActivity(subscription models.Subscription) error {
if err != nil {
return err
}
pushRegistorJob(subscription.InboxURL, jsonData)
pushRegisterJob(subscription.InboxURL, jsonData)

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions control/follow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestListFollows(t *testing.T) {
app := followCmdInit()

buffer := new(bytes.Buffer)
app.SetOutput(buffer)
app.SetOut(buffer)

relayState.RedisClient.HMSet("relay:pending:example.com", map[string]interface{}{
"inbox_url": "https://example.com/inbox",
Expand Down Expand Up @@ -95,7 +95,7 @@ func TestInvalidFollow(t *testing.T) {
app := followCmdInit()

buffer := new(bytes.Buffer)
app.SetOutput(buffer)
app.SetOut(buffer)

app.SetArgs([]string{"accept", "unknown.tld"})
app.Execute()
Expand All @@ -112,7 +112,7 @@ func TestInvalidRejectFollow(t *testing.T) {
app := followCmdInit()

buffer := new(bytes.Buffer)
app.SetOutput(buffer)
app.SetOut(buffer)

app.SetArgs([]string{"reject", "unknown.tld"})
app.Execute()
Expand Down
Loading

0 comments on commit f059214

Please sign in to comment.