Skip to content

Commit

Permalink
rework test files into folder per model
Browse files Browse the repository at this point in the history
add login.html for GS316EP
  • Loading branch information
nitram509 committed Mar 20, 2024
1 parent a3e3ec7 commit 96dcfbd
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 8 deletions.
57 changes: 52 additions & 5 deletions login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,55 @@ import (
_ "embed"
"github.com/corbym/gocrest/is"
"github.com/corbym/gocrest/then"
"os"
"path/filepath"
"strings"
"testing"
)

func TestGetSeedValueFromLoginHtml(t *testing.T) {
randomVal, err := getSeedValueFromLoginHtml(strings.NewReader(loginCgiHtml))
//go:embed test-data/GS308EP/login.cgi.html
var loginCgiHtml string

//go:embed test-data/GS308EPP/login.cgi.html
var loginCgiHtmlGs308EPP string

//go:embed test-data/GS316EP/login.html
var loginCgiHtmlGs316EP string

func TestGetSeedValueFromLogin(t *testing.T) {
tests := []struct {
model string
fileName string
expectedSeed string
}{
{
model: "GS308EP",
fileName: "login.cgi.html",
expectedSeed: "1761741982",
},
{
model: "GS308EPP",
fileName: "login.cgi.html",
expectedSeed: "1387882569",
},
{
model: "GS316EP",
fileName: "login.html",
expectedSeed: "885340480",
},
}
for _, test := range tests {
t.Run(test.model, func(t *testing.T) {
testGetSeedValueFromLogin(t, test.model, test.fileName, test.expectedSeed)
})
}
}

func testGetSeedValueFromLogin(t *testing.T, model string, fileName string, exxpectedSeed string) {
htmlBytes := loadTestFile(model, fileName)
randomVal, err := getSeedValueFromLoginHtml(strings.NewReader(string(htmlBytes)))

then.AssertThat(t, randomVal, is.EqualTo("1761741982"))
then.AssertThat(t, randomVal, is.EqualTo(exxpectedSeed))
then.AssertThat(t, err, is.Nil())
}

Expand All @@ -21,5 +62,11 @@ func TestEncryptPassword(t *testing.T) {
then.AssertThat(t, val, is.EqualTo("d1f4394e3e212ab4f06e08c54477a237"))
}

//go:embed test-data/login.cgi.html
var loginCgiHtml string
func loadTestFile(model string, fileName string) []byte {
fullFileName := filepath.Join("test-data", model, fileName)
bytes, err := os.ReadFile(fullFileName)
if err != nil {
panic(err)
}
return bytes
}
2 changes: 1 addition & 1 deletion poe_set_port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,5 @@ func TestCollectChangedPoePortConfiguration(t *testing.T) {
then.AssertThat(t, changed[0].PortName, is.EqualTo("port 1"))
}

//go:embed test-data/PoEPortConfig.cgi.html
//go:embed test-data/GS308EP/PoEPortConfig.cgi.html
var getPoePortConfig string
2 changes: 1 addition & 1 deletion poe_settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ func TestPrettyPrintJsonSettings(t *testing.T) {
prettyPrintSettings(JsonFormat, settings)
}

//go:embed test-data/PoEPortConfig.cgi.html
//go:embed test-data/GS308EP/PoEPortConfig.cgi.html
var getPoePortConfigCgiHtml string
2 changes: 1 addition & 1 deletion poe_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ func TestPrettyPrintJsonStatus(t *testing.T) {
prettyPrintStatus(JsonFormat, statuses)
}

//go:embed test-data/getPoePortStatus.cgi.html
//go:embed test-data/GS308EP/getPoePortStatus.cgi.html
var getPoePortStatusCgiHtml string
File renamed without changes.
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions test-data/GS316EP/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Pragma" content="no-cache">
<title>NETGEAR GS316EP</title>
<link rel="stylesheet" type="text/css" href="/loginPage.css">
<!LANGUAGE_SCRIPT_TYPE_KEY>
<script src="/jquery.min.js" type="text/javascript"></script>
<script src="/jquery_migrate_min.js" type="text/javascript"></script>
<script src="/jquery.md5.js" type="text/javascript"></script>
<script src="/loginPage.js" type="text/javascript"></script>
<script type='text/javascript' language='JavaScript'>
function submitLogin()
{
encryptPwd();
document.forms[0].submit();
return true;
}
function onEnterSub(e)
{
var whKey;

if (window.event)
{
whKey = e.keyCode;
}
else if (e.which)
{
whKey = e.which;
}

if(whKey == '13')
{
submitLogin();
}
}
</script>
</head>
<body id="loginBody">
<form name="login" method="post" onSubmit="return false;" action="/redirect.html" autocomplete="off">
<input type="hidden" id="submitPwd" name="LoginPassword" value="">
<div id="loginWrapper">
<div class="netgearLogo" style="height:214px;">
<a href="http://www.netgear.com/" target="_blank">
<img src="/switch_logo_login.svg" style="border:none;">
</a>
<span class="p-name">GS316EP</span>
</div>
<div class="summary" style="width:85%;"><span class="lang">If logging in for the first time, log in with your switch's default password which is found on the label on the bottom of the switch.</span></div>
<div id="passwordWrapperdiv" class="passwordWrapper">
<div id="loginPasswordDiv" class="input-wrapper ng-init-block">

<div class="input-title editHead active lang">Password</div>
<input id="Password" class="editBody wideInput" type="password" value="" maxlength="20" onkeypress="onEnterSub(event);" autocomplete="off">
<div onclick="toggleEye()" class="switch-eye">
<i class="icon-eye-off show"></i>
<i class="icon-eye-on"></i>
</div>
<input type="hidden" id='rand' value="885340480" disabled>
<span id="loginPageErrorMsg" class="validationRed"></span>

</div>
</div>

<div class="loginButton modalFooterBlockOne apply waves-effect waves-gray btn">
<div class="btnWrapper" onclick="submitLogin()">
<a class="lang">LOG IN</a>
</div>
</div>
</div>
</form>
</body>
</html>

0 comments on commit 96dcfbd

Please sign in to comment.