You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

118 lines
2.6 KiB

package burnpaste
import (
"bytes"
"log"
"testing"
)
// Endpoint must end with a slash.
const endpoint = "http://localhost:2323/"
// Testing constants
const testMessage = "This is a paste."
const testMessageHash = "ee2ec014a1194908209736c6e89c843fe61e94f8763afef7bb12999c5da02b55"
func TestHash(t *testing.T) {
hash := Hash([]byte(testMessage))
if hash != testMessageHash {
t.Errorf("Wrong hash: %s", hash)
} else {
log.Print("Hash correct.")
}
}
func TestWrite(t *testing.T) {
url, err := Write(endpoint, []byte(testMessage))
if err != nil {
t.Errorf("We got error: %s", err.Error())
} else {
log.Printf("url: %s", url)
}
if url == endpoint+"read/"+testMessageHash {
log.Print("URL is correct.")
} else {
t.Errorf("Bad URL: %s", url)
}
}
func TestRead(t *testing.T) {
contents, err := Read(endpoint + "read/" + testMessageHash)
if err != nil {
t.Errorf("We got error: %s", err.Error())
} else {
log.Print("Able to read.")
}
if bytes.Equal(contents, []byte(testMessage)) {
log.Print("Contents are correct.")
} else {
t.Errorf("Contents do not match: %s", contents)
}
}
func TestIsOnion(t *testing.T) {
url := "http://google.com"
status, err := isOnion(url)
if err != nil {
t.Errorf("We got error: %s", err.Error())
} else {
log.Printf("url: %s", url)
}
if status == false {
log.Printf("We know %s is not a .onion", url)
} else {
log.Printf("We think this is a .onion but it's not. %s", url)
}
url = "http://localhost"
status, err = isOnion(url)
if err != nil {
t.Errorf("We got error: %s", err.Error())
} else {
log.Printf("url: %s", url)
}
if status == false {
log.Printf("We know %s is not a .onion", url)
} else {
log.Printf("We think this is a .onion but it's not. %s", url)
}
url = "http://127.0.0.1:2323"
status, err = isOnion(url)
if err != nil {
t.Errorf("We got error: %s", err.Error())
} else {
log.Printf("url: %s", url)
}
if status == false {
log.Printf("We know %s is not a .onion", url)
} else {
log.Printf("We think this is a .onion but it's not. %s", url)
}
url = "http://somesite.onion"
status, err = isOnion(url)
if err != nil {
t.Errorf("We got error: %s", err.Error())
} else {
log.Printf("url: %s", url)
}
if status == true {
log.Printf("We know %s is a .onion", url)
} else {
log.Printf("We think this is not a .onion but it is. %s", url)
}
url = "http://somesite.onion/somestuff/thing.txt"
status, err = isOnion(url)
if err != nil {
t.Errorf("We got error: %s", err.Error())
} else {
log.Printf("url: %s", url)
}
if status == true {
log.Printf("We know %s is a .onion", url)
} else {
log.Printf("We think this is not a .onion but it is. %s", url)
}
}