By default, artifacts that are not type 0x0004 artifacts of this IdP are still sent to the IdP unchanged, as before; with RequireStandardArtifacts they are refused without contacting the IdP.
(t *testing.T)
| 133 | // still sent to the IdP unchanged, as before; with RequireStandardArtifacts |
| 134 | // they are refused without contacting the IdP. |
| 135 | func TestArtifactDecodingStrictness(t *testing.T) { |
| 136 | e, s := artifactdecSetup(t) |
| 137 | |
| 138 | wrongSource := sha1.Sum([]byte("https://other-idp.example.com/metadata")) //nolint:gosec // G401: SourceID |
| 139 | tooLong := base64.StdEncoding.EncodeToString(append(append([]byte{0x00, 0x04, 0x00, 0x00}, make([]byte, 40)...), 0x00)) |
| 140 | type0002 := base64.StdEncoding.EncodeToString(append([]byte{0x00, 0x02, 0x00, 0x00}, make([]byte, 40)...)) |
| 141 | cases := []struct { |
| 142 | name string |
| 143 | artifact string |
| 144 | kind error |
| 145 | msg string |
| 146 | }{ |
| 147 | {"not base64", "the-artifact", ErrMalformedMessage, "invalid artifact: artifact is not valid base64: illegal base64 data at input byte 3"}, |
| 148 | {"too short", base64.StdEncoding.EncodeToString([]byte{0x00}), ErrMalformedMessage, "invalid artifact: artifact is 1 bytes long, too short for a TypeCode"}, |
| 149 | {"wrong length", tooLong, ErrMalformedMessage, "invalid artifact: type 0x0004 artifact is 45 bytes long, expected 44"}, |
| 150 | {"wrong TypeCode", type0002, ErrUnsupported, "invalid artifact: artifact has TypeCode 0x0002, only 0x0004 is supported"}, |
| 151 | {"wrong SourceID", artifactdecMake(0, wrongSource, 0x05), ErrIssuerMismatch, ""}, |
| 152 | } |
| 153 | |
| 154 | for _, c := range cases { |
| 155 | t.Run(c.name+" is sent unchanged by default", func(t *testing.T) { |
| 156 | s.artifacts = nil |
| 157 | _, err := e.sp.ParseResponse(spcovArtifactRequest(c.artifact), []string{spcovRequestID}) |
| 158 | assert.NilError(t, err) |
| 159 | assert.Check(t, is.DeepEqual([]string{c.artifact}, s.artifacts)) |
| 160 | }) |
| 161 | t.Run(c.name+" is refused with RequireStandardArtifacts", func(t *testing.T) { |
| 162 | s.artifacts = nil |
| 163 | sp := *e.sp |
| 164 | sp.RequireStandardArtifacts = true |
| 165 | _, err := sp.ParseResponse(spcovArtifactRequest(c.artifact), []string{spcovRequestID}) |
| 166 | privateErr := spcovPrivateErr(t, err) |
| 167 | assert.Check(t, is.ErrorIs(privateErr, ErrArtifactResolution)) |
| 168 | assert.Check(t, is.ErrorIs(privateErr, c.kind)) |
| 169 | if c.msg != "" { |
| 170 | assert.Check(t, is.Error(privateErr, c.msg)) |
| 171 | } |
| 172 | assert.Check(t, is.Len(s.artifacts, 0), "the IdP must not be contacted") |
| 173 | }) |
| 174 | } |
| 175 | |
| 176 | t.Run("standard artifact is accepted with RequireStandardArtifacts", func(t *testing.T) { |
| 177 | s.paths = nil |
| 178 | sp := *e.sp |
| 179 | sp.RequireStandardArtifacts = true |
| 180 | _, err := sp.ParseResponse(spcovArtifactRequest(artifactdecMake(7, artifactdecIDPSourceID(), 0x06)), []string{spcovRequestID}) |
| 181 | assert.NilError(t, err) |
| 182 | assert.Check(t, is.DeepEqual([]string{"/ars7"}, s.paths)) |
| 183 | }) |
| 184 | |
| 185 | t.Run("IdP metadata without entityID", func(t *testing.T) { |
| 186 | sp := *e.sp |
| 187 | sp.RequireStandardArtifacts = true |
| 188 | md := *sp.IDPMetadata |
| 189 | md.EntityID = "" |
| 190 | sp.IDPMetadata = &md |
| 191 | _, err := sp.handleArtifactRequest(context.Background(), artifactdecMake(7, artifactdecIDPSourceID(), 0x07), nil) |
| 192 | privateErr := spcovPrivateErr(t, err) |
nothing calls this directly
no test coverage detected