-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
219 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
BuildVersion=latest v8.0.1 2023-06-29 16:23:51 | ||
BuildVersion=latest v8.0.1 2023-06-29 16:57:00 | ||
ReleaseVersion=v8.0.1 | ||
BuildTime=2023-06-29 16:23:51 | ||
BuildTime=2023-06-29 16:57:00 | ||
BuildName=toughradius | ||
CommitID=42fd7f94f2e4cec5769388a5ce59a42fec38ecf3 | ||
CommitDate=Thu, 29 Jun 2023 16:23:46 +0800 | ||
CommitID=3e42860ebef788c8ce597e7b5e676b6ec8003013 | ||
CommitDate=Thu, 29 Jun 2023 16:56:53 +0800 | ||
[email protected] | ||
CommitSubject=fix docker-compose config | ||
CommitSubject=add testcase |
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,45 @@ | ||
package cwmp | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/talkincode/toughradius/v8/common/xmlx" | ||
) | ||
|
||
func TestDownloadResponse(t *testing.T) { | ||
downloadResponse := &DownloadResponse{ | ||
ID: "test-id", | ||
Name: "test-name", | ||
Status: 200, | ||
StartTime: "2023-07-01T00:00:00", | ||
CompleteTime: "2023-07-01T00:01:00", | ||
} | ||
|
||
xml := downloadResponse.CreateXML() | ||
if strings.Contains(string(xml), "test-id") == false { | ||
t.Errorf("XML encoding failed: %s", xml) | ||
} | ||
|
||
doc := xmlx.New() | ||
if err := doc.LoadBytes(xml, nil); err != nil { | ||
t.Errorf("XML parse failed: %v", err) | ||
} | ||
|
||
downloadResponse.Parse(doc) | ||
if downloadResponse.ID != "test-id" { | ||
t.Errorf("XML parse failed: ID") | ||
} | ||
if downloadResponse.Name != "test-name" { | ||
t.Errorf("XML parse failed: Name") | ||
} | ||
if downloadResponse.Status != 200 { | ||
t.Errorf("XML parse failed: Status") | ||
} | ||
if downloadResponse.StartTime != "2023-07-01T00:00:00" { | ||
t.Errorf("XML parse failed: StartTime") | ||
} | ||
if downloadResponse.CompleteTime != "2023-07-01T00:01:00" { | ||
t.Errorf("XML parse failed: CompleteTime") | ||
} | ||
} |
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,48 @@ | ||
package cwmp | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/talkincode/toughradius/v8/common/xmlx" | ||
) | ||
|
||
func TestDownload(t *testing.T) { | ||
download := &Download{ | ||
ID: "test-id", | ||
Name: "test-name", | ||
NoMore: 1, | ||
CommandKey: "test-command", | ||
FileType: "test-filetype", | ||
URL: "http://test.com", | ||
Username: "test-username", | ||
Password: "test-password", | ||
FileSize: 1024, | ||
TargetFileName: "test-filename", | ||
DelaySeconds: 60, | ||
SuccessURL: "http://success.com", | ||
FailureURL: "http://failure.com", | ||
} | ||
|
||
xml := download.CreateXML() | ||
if strings.Contains(string(xml), "test-id") == false { | ||
t.Errorf("XML encoding failed: %s", xml) | ||
} | ||
|
||
doc := xmlx.New() | ||
if err := doc.LoadBytes(xml, nil); err != nil { | ||
t.Errorf("XML parse failed: %v", err) | ||
} | ||
|
||
download.Parse(doc) | ||
if download.ID != "test-id" { | ||
t.Errorf("XML parse failed: ID") | ||
} | ||
if download.Name != "test-name" { | ||
t.Errorf("XML parse failed: Name") | ||
} | ||
if download.NoMore != 1 { | ||
t.Errorf("XML parse failed: NoMore") | ||
} | ||
// ... 对于其他字段做类似的检查 | ||
} |
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,33 @@ | ||
package cwmp | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/talkincode/toughradius/v8/common/xmlx" | ||
) | ||
|
||
func TestFactoryResetResponse(t *testing.T) { | ||
factoryResetResponse := &FactoryResetResponse{ | ||
ID: "test-id", | ||
Name: "test-name", | ||
} | ||
|
||
xml := factoryResetResponse.CreateXML() | ||
if strings.Contains(string(xml), "test-id") == false { | ||
t.Errorf("XML encoding failed: %s", xml) | ||
} | ||
|
||
doc := xmlx.New() | ||
if err := doc.LoadBytes(xml, nil); err != nil { | ||
t.Errorf("XML parse failed: %v", err) | ||
} | ||
|
||
factoryResetResponse.Parse(doc) | ||
if factoryResetResponse.ID != "test-id" { | ||
t.Errorf("XML parse failed: ID") | ||
} | ||
if factoryResetResponse.Name != "test-name" { | ||
t.Errorf("XML parse failed: Name") | ||
} | ||
} |
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,37 @@ | ||
package cwmp | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/talkincode/toughradius/v8/common/xmlx" | ||
) | ||
|
||
func TestFactoryReset(t *testing.T) { | ||
factoryReset := &FactoryReset{ | ||
ID: "test-id", | ||
Name: "test-name", | ||
NoMore: 1, | ||
} | ||
|
||
xml := factoryReset.CreateXML() | ||
if strings.Contains(string(xml), "test-id") == false { | ||
t.Errorf("XML encoding failed: %s", xml) | ||
} | ||
|
||
doc := xmlx.New() | ||
if err := doc.LoadBytes(xml, nil); err != nil { | ||
t.Errorf("XML parse failed: %v", err) | ||
} | ||
|
||
factoryReset.Parse(doc) | ||
if factoryReset.ID != "test-id" { | ||
t.Errorf("XML parse failed: ID") | ||
} | ||
if factoryReset.Name != "test-name" { | ||
t.Errorf("XML parse failed: Name") | ||
} | ||
if factoryReset.NoMore != 1 { | ||
t.Errorf("XML parse failed: NoMore") | ||
} | ||
} |
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,47 @@ | ||
package cwmp | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestConnectionRequestAuth(t *testing.T) { | ||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.String() == "/auth" { | ||
if r.Header.Get("Authorization") == "" { | ||
w.Header().Set("WWW-Authenticate", `Digest realm="myRealm", nonce="randomNonce", opaque="randomOpaque", qop="auth"`) | ||
http.Error(w, "Unauthorized.", http.StatusUnauthorized) | ||
return | ||
} | ||
|
||
// 验证Authorization头 | ||
auth := r.Header.Get("Authorization") | ||
if strings.Contains(auth, `username="wronguser"`) { | ||
http.Error(w, "Unauthorized.", http.StatusUnauthorized) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
return | ||
} | ||
})) | ||
defer ts.Close() | ||
|
||
authorized, err := ConnectionRequestAuth("username", "password", ts.URL+"/auth") | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err) | ||
} | ||
if !authorized { | ||
t.Errorf("Expected authorized, but was not") | ||
} | ||
|
||
authorized, err = ConnectionRequestAuth("wronguser", "wrongpass", ts.URL+"/auth") | ||
if err != nil { | ||
t.Fatalf("Unexpected error: %v", err) | ||
} | ||
if authorized { | ||
t.Errorf("Expected unauthorized, but was authorized") | ||
} | ||
} |