...

Source file src/github.com/letsencrypt/boulder/web/send_error_test.go

Documentation: github.com/letsencrypt/boulder/web

     1  package web
     2  
     3  import (
     4  	"errors"
     5  	"net/http/httptest"
     6  	"testing"
     7  
     8  	berrors "github.com/letsencrypt/boulder/errors"
     9  	"github.com/letsencrypt/boulder/identifier"
    10  	"github.com/letsencrypt/boulder/log"
    11  	"github.com/letsencrypt/boulder/test"
    12  )
    13  
    14  func TestSendErrorSubProblemNamespace(t *testing.T) {
    15  	rw := httptest.NewRecorder()
    16  	prob := ProblemDetailsForError((&berrors.BoulderError{
    17  		Type:   berrors.Malformed,
    18  		Detail: "bad",
    19  	}).WithSubErrors(
    20  		[]berrors.SubBoulderError{
    21  			{
    22  				Identifier: identifier.DNSIdentifier("example.com"),
    23  				BoulderError: &berrors.BoulderError{
    24  					Type:   berrors.Malformed,
    25  					Detail: "nop",
    26  				},
    27  			},
    28  			{
    29  				Identifier: identifier.DNSIdentifier("what about example.com"),
    30  				BoulderError: &berrors.BoulderError{
    31  					Type:   berrors.Malformed,
    32  					Detail: "nah",
    33  				},
    34  			},
    35  		}),
    36  		"dfoop",
    37  	)
    38  	SendError(log.NewMock(), rw, &RequestEvent{}, prob, errors.New("it bad"))
    39  
    40  	body := rw.Body.String()
    41  	test.AssertUnmarshaledEquals(t, body, `{
    42  		"type": "urn:ietf:params:acme:error:malformed",
    43  		"detail": "dfoop :: bad",
    44  		"status": 400,
    45  		"subproblems": [
    46  		  {
    47  			"type": "urn:ietf:params:acme:error:malformed",
    48  			"detail": "dfoop :: nop",
    49  			"status": 400,
    50  			"identifier": {
    51  			  "type": "dns",
    52  			  "value": "example.com"
    53  			}
    54  		  },
    55  		  {
    56  			"type": "urn:ietf:params:acme:error:malformed",
    57  			"detail": "dfoop :: nah",
    58  			"status": 400,
    59  			"identifier": {
    60  			  "type": "dns",
    61  			  "value": "what about example.com"
    62  			}
    63  		  }
    64  		]
    65  	  }`)
    66  }
    67  
    68  func TestSendErrorSubProbLogging(t *testing.T) {
    69  	rw := httptest.NewRecorder()
    70  	prob := ProblemDetailsForError((&berrors.BoulderError{
    71  		Type:   berrors.Malformed,
    72  		Detail: "bad",
    73  	}).WithSubErrors(
    74  		[]berrors.SubBoulderError{
    75  			{
    76  				Identifier: identifier.DNSIdentifier("example.com"),
    77  				BoulderError: &berrors.BoulderError{
    78  					Type:   berrors.Malformed,
    79  					Detail: "nop",
    80  				},
    81  			},
    82  			{
    83  				Identifier: identifier.DNSIdentifier("what about example.com"),
    84  				BoulderError: &berrors.BoulderError{
    85  					Type:   berrors.Malformed,
    86  					Detail: "nah",
    87  				},
    88  			},
    89  		}),
    90  		"dfoop",
    91  	)
    92  	logEvent := RequestEvent{}
    93  	SendError(log.NewMock(), rw, &logEvent, prob, errors.New("it bad"))
    94  
    95  	test.AssertEquals(t, logEvent.Error, `400 :: malformed :: dfoop :: bad ["example.com :: malformed :: dfoop :: nop", "what about example.com :: malformed :: dfoop :: nah"]`)
    96  }
    97  

View as plain text