fix(api): mask miner passwords in miners document
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
c0efdfb0ca
commit
1e6ba01d03
2 changed files with 88 additions and 1 deletions
87
miners_document_test.go
Normal file
87
miners_document_test.go
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
package proxy
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestProxy_MinersDocument_Good(t *testing.T) {
|
||||
p := &Proxy{
|
||||
miners: map[int64]*Miner{
|
||||
1: {
|
||||
id: 1,
|
||||
ip: "10.0.0.1:49152",
|
||||
tx: 4096,
|
||||
rx: 512,
|
||||
state: MinerStateReady,
|
||||
diff: 100000,
|
||||
user: "WALLET",
|
||||
password: "secret",
|
||||
rigID: "rig-alpha",
|
||||
agent: "XMRig/6.21.0",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
document := p.MinersDocument()
|
||||
if len(document.Miners) != 1 {
|
||||
t.Fatalf("expected one miner row, got %d", len(document.Miners))
|
||||
}
|
||||
row := document.Miners[0]
|
||||
if len(row) != 10 {
|
||||
t.Fatalf("expected 10 miner columns, got %d", len(row))
|
||||
}
|
||||
if row[7] != "********" {
|
||||
t.Fatalf("expected masked password, got %#v", row[7])
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxy_MinersDocument_Bad(t *testing.T) {
|
||||
var p *Proxy
|
||||
|
||||
document := p.MinersDocument()
|
||||
if len(document.Miners) != 0 {
|
||||
t.Fatalf("expected no miners for a nil proxy, got %d", len(document.Miners))
|
||||
}
|
||||
if len(document.Format) != 10 {
|
||||
t.Fatalf("expected miner format columns to remain stable, got %d", len(document.Format))
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxy_MinersDocument_Ugly(t *testing.T) {
|
||||
p := &Proxy{
|
||||
miners: map[int64]*Miner{
|
||||
1: {
|
||||
id: 1,
|
||||
ip: "10.0.0.1:49152",
|
||||
tx: 4096,
|
||||
rx: 512,
|
||||
state: MinerStateReady,
|
||||
diff: 100000,
|
||||
user: "WALLET",
|
||||
password: "secret-a",
|
||||
rigID: "rig-alpha",
|
||||
agent: "XMRig/6.21.0",
|
||||
},
|
||||
2: {
|
||||
id: 2,
|
||||
ip: "10.0.0.2:49152",
|
||||
tx: 2048,
|
||||
rx: 256,
|
||||
state: MinerStateWaitReady,
|
||||
diff: 50000,
|
||||
user: "WALLET2",
|
||||
password: "secret-b",
|
||||
rigID: "rig-beta",
|
||||
agent: "XMRig/6.22.0",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
document := p.MinersDocument()
|
||||
if len(document.Miners) != 2 {
|
||||
t.Fatalf("expected two miner rows, got %d", len(document.Miners))
|
||||
}
|
||||
for i, row := range document.Miners {
|
||||
if row[7] != "********" {
|
||||
t.Fatalf("expected masked password in row %d, got %#v", i, row[7])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -736,7 +736,7 @@ func (p *Proxy) MinersDocument() MinersDocument {
|
|||
miner.State,
|
||||
miner.Diff,
|
||||
miner.User,
|
||||
miner.Password,
|
||||
"********",
|
||||
miner.RigID,
|
||||
miner.Agent,
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue