func TestNewAuthorization(t *testing.T) { _, _, sa, ra, cleanUp := initAuthorities(t) defer cleanUp() _, err := ra.NewAuthorization(AuthzRequest, 0) test.AssertError(t, err, "Authorization cannot have registrationID == 0") authz, err := ra.NewAuthorization(AuthzRequest, 1) test.AssertNotError(t, err, "NewAuthorization failed") // Verify that returned authz same as DB dbAuthz, err := sa.GetAuthorization(authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) // Verify that the returned authz has the right information test.Assert(t, authz.RegistrationID == 1, "Initial authz did not get the right registration ID") test.Assert(t, authz.Identifier == AuthzRequest.Identifier, "Initial authz had wrong identifier") test.Assert(t, authz.Status == core.StatusPending, "Initial authz not pending") // TODO Verify that challenges are correct test.Assert(t, len(authz.Challenges) == 3, "Incorrect number of challenges returned") test.Assert(t, authz.Challenges[0].Type == core.ChallengeTypeSimpleHTTP, "Challenge 0 not SimpleHTTP") test.Assert(t, authz.Challenges[1].Type == core.ChallengeTypeDVSNI, "Challenge 1 not DVSNI") test.Assert(t, authz.Challenges[2].Type == core.ChallengeTypeDNS, "Challenge 2 not DNS") t.Log("DONE TestNewAuthorization") }
func TestOnValidationUpdateSuccess(t *testing.T) { _, sa, ra, fclk, cleanUp := initAuthorities(t) defer cleanUp() authzUpdated, err := sa.NewPendingAuthorization(AuthzInitial) test.AssertNotError(t, err, "Failed to create new pending authz") expires := fclk.Now().Add(300 * 24 * time.Hour) authzUpdated.Expires = &expires sa.UpdatePendingAuthorization(authzUpdated) // Simulate a successful simpleHTTP challenge authzFromVA := authzUpdated authzFromVA.Challenges[0].Status = core.StatusValid ra.OnValidationUpdate(authzFromVA) // Verify that the Authz in the DB is the same except for Status->StatusValid authzFromVA.Status = core.StatusValid dbAuthz, err := sa.GetAuthorization(authzFromVA.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") t.Log("authz from VA: ", authzFromVA) t.Log("authz from DB: ", dbAuthz) assertAuthzEqual(t, authzFromVA, dbAuthz) }
func TestOnValidationUpdate(t *testing.T) { _, _, sa, ra := initAuthorities(t) AuthzUpdated.ID, _ = sa.NewPendingAuthorization() sa.UpdatePendingAuthorization(AuthzUpdated) // Simulate a successful simpleHTTPS challenge AuthzFromVA = AuthzUpdated AuthzFromVA.Challenges[0].Status = core.StatusValid ra.OnValidationUpdate(AuthzFromVA) // Verify that the Authz in the DB is the same except for Status->StatusValid AuthzFromVA.Status = core.StatusValid dbAuthz, err := sa.GetAuthorization(AuthzFromVA.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, AuthzFromVA, dbAuthz) t.Log(" ~~> from VA: ", AuthzFromVA.Status) t.Log(" ~~> from DB: ", dbAuthz.Status) // If we get to here, we'll use this authorization for the next test AuthzFinal = dbAuthz // TODO Test failure cases t.Log("DONE TestOnValidationUpdate") }
func TestUpdateAuthorization(t *testing.T) { va, sa, ra, _, cleanUp := initAuthorities(t) defer cleanUp() // We know this is OK because of TestNewAuthorization authz, err := ra.NewAuthorization(AuthzRequest, Registration.ID) test.AssertNotError(t, err, "NewAuthorization failed") response, err := makeResponse(authz.Challenges[ResponseIndex]) test.AssertNotError(t, err, "Unable to construct response to challenge") authz, err = ra.UpdateAuthorization(authz, ResponseIndex, response) test.AssertNotError(t, err, "UpdateAuthorization failed") // Verify that returned authz same as DB dbAuthz, err := sa.GetAuthorization(authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) // Verify that the VA got the authz, and it's the same as the others test.Assert(t, va.Called, "Authorization was not passed to the VA") assertAuthzEqual(t, authz, va.Argument) // Verify that the responses are reflected test.Assert(t, len(va.Argument.Challenges) > 0, "Authz passed to VA has no challenges") t.Log("DONE TestUpdateAuthorization") }
func TestNewAuthorization(t *testing.T) { _, sa, ra, _, cleanUp := initAuthorities(t) defer cleanUp() _, err := ra.NewAuthorization(AuthzRequest, 0) test.AssertError(t, err, "Authorization cannot have registrationID == 0") authz, err := ra.NewAuthorization(AuthzRequest, Registration.ID) test.AssertNotError(t, err, "NewAuthorization failed") // Verify that returned authz same as DB dbAuthz, err := sa.GetAuthorization(authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) // Verify that the returned authz has the right information test.Assert(t, authz.RegistrationID == Registration.ID, "Initial authz did not get the right registration ID") test.Assert(t, authz.Identifier == AuthzRequest.Identifier, "Initial authz had wrong identifier") test.Assert(t, authz.Status == core.StatusPending, "Initial authz not pending") // TODO Verify that challenges are correct test.Assert(t, len(authz.Challenges) == len(SupportedChallenges), "Incorrect number of challenges returned") test.Assert(t, SupportedChallenges[authz.Challenges[0].Type], fmt.Sprintf("Unsupported challenge: %s", authz.Challenges[0].Type)) test.Assert(t, SupportedChallenges[authz.Challenges[1].Type], fmt.Sprintf("Unsupported challenge: %s", authz.Challenges[1].Type)) test.Assert(t, authz.Challenges[0].IsSane(false), "Challenge 0 is not sane") test.Assert(t, authz.Challenges[1].IsSane(false), "Challenge 1 is not sane") t.Log("DONE TestNewAuthorization") }
func TestUpdateAuthorization(t *testing.T) { _, va, sa, ra := initAuthorities(t) AuthzInitial.ID, _ = sa.NewPendingAuthorization() sa.UpdatePendingAuthorization(AuthzInitial) authz, err := ra.UpdateAuthorization(AuthzInitial, ResponseIndex, Response) test.AssertNotError(t, err, "UpdateAuthorization failed") // Verify that returned authz same as DB dbAuthz, err := sa.GetAuthorization(authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) // Verify that the VA got the authz, and it's the same as the others test.Assert(t, va.Called, "Authorization was not passed to the VA") assertAuthzEqual(t, authz, va.Argument) // Verify that the responses are reflected test.Assert(t, len(va.Argument.Challenges) > 0, "Authz passed to VA has no challenges") simpleHttps := va.Argument.Challenges[0] test.Assert(t, simpleHttps.Path == Response.Path, "simpleHttps changed") // If we get to here, we'll use this authorization for the next test AuthzUpdated = authz // TODO Test failure cases t.Log("DONE TestUpdateAuthorization") }
func TestUpdateAuthorizationNewRPC(t *testing.T) { va, sa, ra, _, cleanUp := initAuthorities(t) defer cleanUp() // We know this is OK because of TestNewAuthorization authz, err := ra.NewAuthorization(ctx, AuthzRequest, Registration.ID) test.AssertNotError(t, err, "NewAuthorization failed") response, err := makeResponse(authz.Challenges[ResponseIndex]) test.AssertNotError(t, err, "Unable to construct response to challenge") authz.Challenges[ResponseIndex].Type = core.ChallengeTypeDNS01 va.RecordsReturn = []core.ValidationRecord{ {Hostname: "example.com"}} va.ProblemReturn = nil authz, err = ra.UpdateAuthorization(ctx, authz, ResponseIndex, response) test.AssertNotError(t, err, "UpdateAuthorization failed") // Verify that returned authz same as DB dbAuthz, err := sa.GetAuthorization(ctx, authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) // Verify that the VA got the authz, and it's the same as the others test.Assert(t, va.Called, "Authorization was not passed to the VA") assertAuthzEqual(t, authz, va.Argument) // Verify that the responses are reflected test.Assert(t, len(va.Argument.Challenges) > 0, "Authz passed to VA has no challenges") test.Assert(t, authz.Challenges[ResponseIndex].Status == core.StatusValid, "challenge was not marked as valid") t.Log("DONE TestUpdateAuthorizationNewRPC") }
func TestOnValidationUpdateFailure(t *testing.T) { _, sa, ra, _, cleanUp := initAuthorities(t) defer cleanUp() authzFromVA, _ := sa.NewPendingAuthorization(AuthzUpdated) sa.UpdatePendingAuthorization(AuthzUpdated) authzFromVA.Challenges[0].Status = core.StatusInvalid err := ra.OnValidationUpdate(authzFromVA) test.AssertNotError(t, err, "unable to update validation") authzFromVA.Status = core.StatusInvalid dbAuthz, err := sa.GetAuthorization(authzFromVA.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authzFromVA, dbAuthz) }
func TestOnValidationUpdateFailure(t *testing.T) { _, sa, ra, fclk, cleanUp := initAuthorities(t) defer cleanUp() authzFromVA, _ := sa.NewPendingAuthorization(AuthzInitial) expires := fclk.Now().Add(300 * 24 * time.Hour) authzFromVA.Expires = &expires sa.UpdatePendingAuthorization(authzFromVA) authzFromVA.Challenges[0].Status = core.StatusInvalid err := ra.OnValidationUpdate(authzFromVA) test.AssertNotError(t, err, "unable to update validation") authzFromVA.Status = core.StatusInvalid dbAuthz, err := sa.GetAuthorization(authzFromVA.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authzFromVA, dbAuthz) }
func TestNewAuthorizationCapitalLetters(t *testing.T) { _, sa, ra, _, cleanUp := initAuthorities(t) defer cleanUp() authzReq := core.Authorization{ Identifier: core.AcmeIdentifier{ Type: core.IdentifierDNS, Value: "NOT-example.COM", }, } authz, err := ra.NewAuthorization(authzReq, Registration.ID) test.AssertNotError(t, err, "NewAuthorization failed") test.AssertEquals(t, "not-example.com", authz.Identifier.Value) dbAuthz, err := sa.GetAuthorization(authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) }
func TestOnValidationUpdate(t *testing.T) { _, _, sa, ra := initAuthorities(t) AuthzUpdated, _ = sa.NewPendingAuthorization(AuthzUpdated) sa.UpdatePendingAuthorization(AuthzUpdated) // Simulate a successful simpleHTTP challenge authzFromVA := AuthzUpdated authzFromVA.Challenges[0].Status = core.StatusValid ra.OnValidationUpdate(authzFromVA) // Verify that the Authz in the DB is the same except for Status->StatusValid authzFromVA.Status = core.StatusValid dbAuthz, err := sa.GetAuthorization(authzFromVA.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authzFromVA, dbAuthz) t.Log(" ~~> from VA: ", authzFromVA.Status) t.Log(" ~~> from DB: ", dbAuthz.Status) t.Log("DONE TestOnValidationUpdate") }
func TestNewAuthorization(t *testing.T) { _, sa, ra, _, cleanUp := initAuthorities(t) defer cleanUp() _, err := ra.NewAuthorization(AuthzRequest, 0) test.AssertError(t, err, "Authorization cannot have registrationID == 0") authz, err := ra.NewAuthorization(AuthzRequest, Registration.ID) test.AssertNotError(t, err, "NewAuthorization failed") // Verify that returned authz same as DB dbAuthz, err := sa.GetAuthorization(authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) // Verify that the returned authz has the right information test.Assert(t, authz.RegistrationID == Registration.ID, "Initial authz did not get the right registration ID") test.Assert(t, authz.Identifier == AuthzRequest.Identifier, "Initial authz had wrong identifier") test.Assert(t, authz.Status == core.StatusPending, "Initial authz not pending") // TODO Verify that challenges are correct // TODO(https://github.com/letsencrypt/boulder/issues/894): Update these lines test.Assert(t, len(authz.Challenges) == 4, "Incorrect number of challenges returned") test.Assert(t, authz.Challenges[0].Type == core.ChallengeTypeSimpleHTTP, "Challenge 0 not SimpleHTTP") test.Assert(t, authz.Challenges[1].Type == core.ChallengeTypeDVSNI, "Challenge 1 not DVSNI") // TODO(https://github.com/letsencrypt/boulder/issues/894): Delete these lines test.Assert(t, authz.Challenges[2].Type == core.ChallengeTypeHTTP01, "Challenge 2 not http-00") test.Assert(t, authz.Challenges[3].Type == core.ChallengeTypeTLSSNI01, "Challenge 3 not tlssni-00") test.Assert(t, authz.Challenges[0].IsSane(false), "Challenge 0 is not sane") test.Assert(t, authz.Challenges[1].IsSane(false), "Challenge 1 is not sane") // TODO(https://github.com/letsencrypt/boulder/issues/894): Delete these lines test.Assert(t, authz.Challenges[2].IsSane(false), "Challenge 2 is not sane") test.Assert(t, authz.Challenges[3].IsSane(false), "Challenge 3 is not sane") t.Log("DONE TestNewAuthorization") }
func TestUpdateAuthorization(t *testing.T) { _, va, sa, ra, cleanUp := initAuthorities(t) defer cleanUp() AuthzInitial, _ = sa.NewPendingAuthorization(AuthzInitial) sa.UpdatePendingAuthorization(AuthzInitial) authz, err := ra.UpdateAuthorization(AuthzInitial, ResponseIndex, Response) test.AssertNotError(t, err, "UpdateAuthorization failed") // Verify that returned authz same as DB dbAuthz, err := sa.GetAuthorization(authz.ID) test.AssertNotError(t, err, "Could not fetch authorization from database") assertAuthzEqual(t, authz, dbAuthz) // Verify that the VA got the authz, and it's the same as the others test.Assert(t, va.Called, "Authorization was not passed to the VA") assertAuthzEqual(t, authz, va.Argument) // Verify that the responses are reflected test.Assert(t, len(va.Argument.Challenges) > 0, "Authz passed to VA has no challenges") t.Log("DONE TestUpdateAuthorization") }