Просмотр исходного кода

Add challenge unmarshal test cases.

Ivan Bertona 6 лет назад
Родитель
Сommit
6b5a2b17b5
1 измененных файлов с 27 добавлено и 1 удалено
  1. 27 1
      acme/challenge_test.go

+ 27 - 1
acme/challenge_test.go

@@ -433,7 +433,7 @@ func TestChallengeUnmarshal(t *testing.T) {
 				err: ServerInternalErr(errors.New("error unmarshaling challenge type: unexpected end of JSON input")),
 			}
 		},
-		"fail/unexpected-type": func(t *testing.T) test {
+		"fail/unexpected-type-http": func(t *testing.T) test {
 			httpCh, err := newHTTPCh()
 			assert.FatalError(t, err)
 			_httpCh, ok := httpCh.(*http01Challenge)
@@ -446,6 +446,32 @@ func TestChallengeUnmarshal(t *testing.T) {
 				err: ServerInternalErr(errors.New("unexpected challenge type foo")),
 			}
 		},
+		"fail/unexpected-type-alpn": func(t *testing.T) test {
+			tlsALPNCh, err := newTLSALPNCh()
+			assert.FatalError(t, err)
+			_tlsALPNCh, ok := tlsALPNCh.(*tlsALPN01Challenge)
+			assert.Fatal(t, ok)
+			_tlsALPNCh.baseChallenge.Type = "foo"
+			b, err := json.Marshal(tlsALPNCh)
+			assert.FatalError(t, err)
+			return test{
+				chb: b,
+				err: ServerInternalErr(errors.New("unexpected challenge type foo")),
+			}
+		},
+		"fail/unexpected-type-dns": func(t *testing.T) test {
+			dnsCh, err := newDNSCh()
+			assert.FatalError(t, err)
+			_tlsALPNCh, ok := dnsCh.(*dns01Challenge)
+			assert.Fatal(t, ok)
+			_tlsALPNCh.baseChallenge.Type = "foo"
+			b, err := json.Marshal(dnsCh)
+			assert.FatalError(t, err)
+			return test{
+				chb: b,
+				err: ServerInternalErr(errors.New("unexpected challenge type foo")),
+			}
+		},
 		"ok/dns": func(t *testing.T) test {
 			dnsCh, err := newDNSCh()
 			assert.FatalError(t, err)