mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
chore: refactor proto tests to use ReadDotLines (#520)
Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
@@ -40,21 +40,15 @@ func TestNoTLS(t *testing.T) {
|
|||||||
if !strings.HasPrefix(reply, "+OK") {
|
if !strings.HasPrefix(reply, "+OK") {
|
||||||
t.Fatalf("Initial line is not +OK")
|
t.Fatalf("Initial line is not +OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify CAPA response does not include STLS.
|
||||||
if err := c.PrintfLine("CAPA"); err != nil {
|
if err := c.PrintfLine("CAPA"); err != nil {
|
||||||
t.Fatalf("Failed to send CAPA; %v.", err)
|
t.Fatalf("Failed to send CAPA; %v.", err)
|
||||||
}
|
}
|
||||||
replies := []string{}
|
replies, err := c.ReadDotLines()
|
||||||
for {
|
|
||||||
reply, err := c.ReadLine()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Reading CAPA line failed %v", err)
|
t.Fatalf("Reading CAPA line failed %v", err)
|
||||||
}
|
}
|
||||||
if reply == "." {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
replies = append(replies, reply)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, r := range replies {
|
for _, r := range replies {
|
||||||
if r == "STLS" {
|
if r == "STLS" {
|
||||||
t.Errorf("TLS not enabled but received STLS.")
|
t.Errorf("TLS not enabled but received STLS.")
|
||||||
@@ -110,28 +104,21 @@ func TestStartTLS(t *testing.T) {
|
|||||||
if !strings.HasPrefix(reply, "+OK") {
|
if !strings.HasPrefix(reply, "+OK") {
|
||||||
t.Fatalf("Initial line is not +OK")
|
t.Fatalf("Initial line is not +OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify CAPA response does not include STLS.
|
||||||
if err := c.PrintfLine("CAPA"); err != nil {
|
if err := c.PrintfLine("CAPA"); err != nil {
|
||||||
t.Fatalf("Failed to send CAPA; %v.", err)
|
t.Fatalf("Failed to send CAPA; %v.", err)
|
||||||
}
|
}
|
||||||
replies := []string{}
|
replies, err := c.ReadDotLines()
|
||||||
for {
|
|
||||||
reply, err := c.ReadLine()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Reading CAPA line failed %v", err)
|
t.Fatalf("Reading CAPA line failed %v", err)
|
||||||
}
|
}
|
||||||
if reply == "." {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
replies = append(replies, reply)
|
|
||||||
}
|
|
||||||
|
|
||||||
sawTLS := false
|
sawTLS := false
|
||||||
for _, r := range replies {
|
for _, r := range replies {
|
||||||
if r == "STLS" {
|
if r == "STLS" {
|
||||||
sawTLS = true
|
sawTLS = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !sawTLS {
|
if !sawTLS {
|
||||||
t.Errorf("TLS enabled but no STLS capability.")
|
t.Errorf("TLS enabled but no STLS capability.")
|
||||||
}
|
}
|
||||||
@@ -167,15 +154,10 @@ func TestStartTLS(t *testing.T) {
|
|||||||
if !strings.HasPrefix(reply, "+OK") {
|
if !strings.HasPrefix(reply, "+OK") {
|
||||||
t.Fatalf("CAPA failed: %s", reply)
|
t.Fatalf("CAPA failed: %s", reply)
|
||||||
}
|
}
|
||||||
for {
|
_, err = c.ReadDotLines()
|
||||||
reply, err := c.ReadLine()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Reading CAPA line failed %v", err)
|
t.Fatalf("Reading CAPA line failed %v", err)
|
||||||
}
|
}
|
||||||
if reply == "." {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDupStartTLS(t *testing.T) {
|
func TestDupStartTLS(t *testing.T) {
|
||||||
@@ -196,28 +178,21 @@ func TestDupStartTLS(t *testing.T) {
|
|||||||
if !strings.HasPrefix(reply, "+OK") {
|
if !strings.HasPrefix(reply, "+OK") {
|
||||||
t.Fatalf("Initial line is not +OK")
|
t.Fatalf("Initial line is not +OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify CAPA response includes STLS.
|
||||||
if err := c.PrintfLine("CAPA"); err != nil {
|
if err := c.PrintfLine("CAPA"); err != nil {
|
||||||
t.Fatalf("Failed to send CAPA; %v.", err)
|
t.Fatalf("Failed to send CAPA; %v.", err)
|
||||||
}
|
}
|
||||||
replies := []string{}
|
replies, err := c.ReadDotLines()
|
||||||
for {
|
|
||||||
reply, err := c.ReadLine()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Reading CAPA line failed %v", err)
|
t.Fatalf("Reading CAPA line failed %v", err)
|
||||||
}
|
}
|
||||||
if reply == "." {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
replies = append(replies, reply)
|
|
||||||
}
|
|
||||||
|
|
||||||
sawTLS := false
|
sawTLS := false
|
||||||
for _, r := range replies {
|
for _, r := range replies {
|
||||||
if r == "STLS" {
|
if r == "STLS" {
|
||||||
sawTLS = true
|
sawTLS = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !sawTLS {
|
if !sawTLS {
|
||||||
t.Errorf("TLS enabled but no STLS capability.")
|
t.Errorf("TLS enabled but no STLS capability.")
|
||||||
}
|
}
|
||||||
@@ -298,27 +273,18 @@ func TestForceTLS(t *testing.T) {
|
|||||||
t.Fatalf("Initial line is not +OK")
|
t.Fatalf("Initial line is not +OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify CAPA response does not include STLS.
|
||||||
if err := c.PrintfLine("CAPA"); err != nil {
|
if err := c.PrintfLine("CAPA"); err != nil {
|
||||||
t.Fatalf("Failed to send CAPA; %v.", err)
|
t.Fatalf("Failed to send CAPA; %v.", err)
|
||||||
}
|
}
|
||||||
reply, err = c.ReadLine()
|
replies, err := c.ReadDotLines()
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Reading CAPA reply line failed %v", err)
|
|
||||||
}
|
|
||||||
if !strings.HasPrefix(reply, "+OK") {
|
|
||||||
t.Fatalf("CAPA failed: %s", reply)
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
reply, err := c.ReadLine()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Reading CAPA line failed %v", err)
|
t.Fatalf("Reading CAPA line failed %v", err)
|
||||||
}
|
}
|
||||||
if reply == "STLS" {
|
for _, r := range replies {
|
||||||
|
if r == "STLS" {
|
||||||
t.Errorf("STLS in CAPA in forceTLS mode.")
|
t.Errorf("STLS in CAPA in forceTLS mode.")
|
||||||
}
|
}
|
||||||
if reply == "." {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user