(t *testing.T)
| 666 | } |
| 667 | |
| 668 | func TestQueryAttributesErrors(t *testing.T) { |
| 669 | t.Run("HTTP error status", func(t *testing.T) { |
| 670 | e := aqSetup(t) |
| 671 | s := newAQServer(t, e) |
| 672 | s.status = http.StatusInternalServerError |
| 673 | s.respond = func(*AttributeQuery) []byte { return []byte("<soapenv:Envelope/>") } |
| 674 | _, err := e.sp.QueryAttributes(context.Background(), aqNameID) |
| 675 | assert.Check(t, is.ErrorContains(err, "HTTP status 500")) |
| 676 | }) |
| 677 | t.Run("oversized response", func(t *testing.T) { |
| 678 | e := aqSetup(t) |
| 679 | old := MaxAttributeQueryResponseSize |
| 680 | t.Cleanup(func() { MaxAttributeQueryResponseSize = old }) |
| 681 | MaxAttributeQueryResponseSize = 4096 |
| 682 | s := newAQServer(t, e) |
| 683 | var size int |
| 684 | s.respond = func(query *AttributeQuery) []byte { |
| 685 | buf := e.aqSOAP(t, query, aqOptions{signResponse: true}) |
| 686 | size = len(buf) |
| 687 | return append(buf, bytes.Repeat([]byte(" "), 4096)...) |
| 688 | } |
| 689 | _, err := e.sp.QueryAttributes(context.Background(), aqNameID) |
| 690 | assert.Check(t, is.ErrorContains(err, "response body is larger than 4096 bytes")) |
| 691 | |
| 692 | // At the limit, it is accepted. |
| 693 | MaxAttributeQueryResponseSize = int64(size + 4096) |
| 694 | _, err = e.sp.QueryAttributes(context.Background(), aqNameID) |
| 695 | assert.NilError(t, err) |
| 696 | }) |
| 697 | t.Run("invalid response", func(t *testing.T) { |
| 698 | e := aqSetup(t) |
| 699 | s := newAQServer(t, e) |
| 700 | s.respond = func(query *AttributeQuery) []byte { return e.aqSOAP(t, query, aqOptions{}) } |
| 701 | _, err := e.sp.QueryAttributes(context.Background(), aqNameID) |
| 702 | assert.Check(t, is.ErrorContains(spcovPrivateErr(t, err), "neither the Response nor its Assertion is signed")) |
| 703 | }) |
| 704 | t.Run("cancelled context", func(t *testing.T) { |
| 705 | e := aqSetup(t) |
| 706 | s := newAQServer(t, e) |
| 707 | s.respond = func(query *AttributeQuery) []byte { return e.aqSOAP(t, query, aqOptions{signResponse: true}) } |
| 708 | ctx, cancel := context.WithCancel(context.Background()) |
| 709 | cancel() |
| 710 | _, err := e.sp.QueryAttributes(ctx, aqNameID) |
| 711 | assert.Check(t, errors.Is(err, context.Canceled), "%v", err) |
| 712 | assert.Check(t, is.Len(s.requests, 0)) |
| 713 | }) |
| 714 | } |
| 715 | |
| 716 | func TestGetAttributeServiceLocation(t *testing.T) { |
| 717 | e := aqSetup(t) |
nothing calls this directly
no test coverage detected