github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/open_resource_discovery/validation_test.go (about) 1 package ord_test 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "strings" 7 "testing" 8 9 "github.com/kyma-incubator/compass/components/director/pkg/accessstrategy" 10 11 "github.com/kyma-incubator/compass/components/director/internal/model" 12 13 ord "github.com/kyma-incubator/compass/components/director/internal/open_resource_discovery" 14 "github.com/kyma-incubator/compass/components/director/pkg/str" 15 "github.com/stretchr/testify/require" 16 ) 17 18 const ( 19 invalidOpenResourceDiscovery = "invalidOpenResourceDiscovery" 20 invalidURL = "invalidURL" 21 invalidOrdID = "invalidOrdId" 22 invalidShortDescriptionLength = 257 // max allowed: 256 23 invalidTitleLength = 256 // max allowed: 255 24 invalidLocalTenantIDLength = 256 //max allowed: 255 25 maxDescriptionLength = 5000 26 invalidVersion = "invalidVersion" 27 invalidPolicyLevel = "invalidPolicyLevel" 28 invalidVendor = "wrongVendor!" 29 invalidType = "invalidType" 30 invalidCustomType = "wrongCustomType" 31 invalidMediaType = "invalid/type" 32 invalidBundleOrdID = "ns:wrongConsumptionBundle:v1" 33 34 unknownVendorOrdID = "nsUNKNOWN:vendor:id:" 35 unknownProductOrdID = "nsUNKNOWN:product:id:" 36 unknownPackageOrdID = "ns:package:UNKNOWN_PACKAGE_ID:v1" 37 unknownBundleOrdID = "ns:consumptionBundle:UNKNOWN_BUNDLE_ID:v1" 38 ) 39 40 var ( 41 invalidJSON = `[ 42 { 43 foo: bar, 44 } 45 ]` 46 47 invalidPackageLinkDueToMissingType = `[ 48 { 49 "url": "https://example.com/en/legal/terms-of-use.html" 50 }, 51 { 52 "type": "client-registration", 53 "url": "https://example2.com/en/legal/terms-of-use.html" 54 } 55 ]` 56 57 invalidPackageLinkDueToWrongType = `[ 58 { 59 "type": "wrongType", 60 "url": "https://example.com/en/legal/terms-of-use.html" 61 }, 62 { 63 "type": "client-registration", 64 "url": "https://example2.com/en/legal/terms-of-use.html" 65 } 66 ]` 67 68 invalidPackageLinkDueToMissingURL = `[ 69 { 70 "type": "payment" 71 }, 72 { 73 "type": "client-registration", 74 "url": "https://example2.com/en/legal/terms-of-use.html" 75 } 76 ]` 77 78 invalidPackageLinkDueToWrongURL = `[ 79 { 80 "type": "payment", 81 "url": "wrongUrl" 82 }, 83 { 84 "type": "client-registration", 85 "url": "https://example2.com/en/legal/terms-of-use.html" 86 } 87 ]` 88 89 invalidPackageLinkDueToWrongFormatOfCustomType = `[ 90 { 91 "type": "custom", 92 "url": "https://example2.com/en/legal/terms-of-use.html", 93 "customType": "%^&wrong:{}" 94 } 95 ]` 96 97 validPackageLinkCorrectFormatOfCustomType = `[ 98 { 99 "type": "custom", 100 "url": "https://example2.com/en/legal/terms-of-use.html", 101 "customType": "name.sap.com:spec.id:v1" 102 } 103 ]` 104 105 invalidPackageLinkTypeWhenProvidedCustomType = `[ 106 { 107 "type": "payment", 108 "url": "https://example2.com/en/legal/terms-of-use.html", 109 "customType": "myCustomType" 110 } 111 ]` 112 113 invalidPackageLinkCustomTypeWhenCustomTypeNotProvided = `[ 114 { 115 "type": "custom", 116 "url": "https://example2.com/en/legal/terms-of-use.html", 117 } 118 ]` 119 120 invalidLinkDueToMissingTitle = `[ 121 { 122 "url": "https://example2.com/en/legal/terms-of-use.html", 123 "description": "foo bar" 124 } 125 ]` 126 invalidLinkDueToMissingURL = `[ 127 { 128 "title": "myTitle" 129 } 130 ]` 131 invalidLinkDueToWrongURL = `[ 132 { 133 "url": "wrongURL", 134 "title": "myTitle" 135 } 136 ]` 137 invalidLinkDueToInvalidLengthOfDescription = `[ 138 { 139 "title": "myTitle", 140 "url": "https://example2.com/en/legal/terms-of-use.html", 141 "description": "%s" 142 } 143 ]` 144 145 invalidPartOfProductsElement = `["invalidValue"]` 146 147 invalidPartOfProductsIntegerElement = `["sap:S4HANA_OD", 992]` 148 149 invalidTagsValue = `["invalid!@#"]` 150 151 invalidTagsValueIntegerElement = `["storage", 992]` 152 153 invalidSupportedUseCasesValue = `["some-value"]` 154 155 validSupportedUseCasesValue = `["mass-extraction"]` 156 157 invalidLabelsWhenValueIsNotArray = `{ 158 "label-key-1": "label-value-1" 159 }` 160 161 invalidLabelsWhenValuesAreNotArrayOfStrings = `{ 162 "label-key-1": [ 163 "label-value-1", 164 992 165 ] 166 }` 167 168 invalidLabelsWhenKeyIsWrong = `{ 169 "invalidKey!@#": [ 170 "label-value-1", 171 "label-value-2" 172 ] 173 }` 174 175 invalidPartnersWhenValueIsNotArray = `{ 176 "partner-key-1": "partner-value-1" 177 }` 178 179 invalidPartnersWhenValuesAreNotArrayOfStrings = `[ 180 "microsoft:vendor:Microsoft", 181 112 182 ]` 183 184 invalidPartnersWhenValuesDoNotSatisfyRegex = `[ 185 "partner:partner:partner", 186 ]` 187 188 invalidCountriesElement = `["DE", "wrongCountry"]` 189 invalidCountriesNonStringElement = `["DE", 992]` 190 191 invalidLineOfBusinessElement = `["sales", "wrongLineOfBusiness!@#"]` 192 invalidLineOfBusinessNonStringElement = `["sales", 992]` 193 194 invalidIndustryElement = `["banking", "wrongIndustry!@#"]` 195 invalidIndustryNonStringElement = `["banking", 992]` 196 197 invalidBundleLinksDueToMissingTitle = `[ 198 { 199 "description": "foo bar", 200 "url": "https://example.com/2018/04/11/testing/" 201 } 202 ]` 203 204 invalidBundleLinksDueToMissingURL = `[ 205 { 206 "description": "foo bar", 207 "title": "myTitle" 208 } 209 ]` 210 invalidBundleLinksDueToWrongURL = `[ 211 { 212 "description": "foo bar", 213 "title": "myTitle", 214 "url": "wrongURL" 215 } 216 ]` 217 218 invalidCredentialsExchangeStrategyDueToMissingType = `[ 219 { 220 "callbackUrl": "http://localhost:8080/credentials/relative" 221 } 222 ]` 223 invalidCredentialsExchangeStrategyDueToWrongType = `[ 224 { 225 "type": "wrongType", 226 "callbackUrl": "http://localhost:8080/credentials/relative" 227 } 228 ]` 229 invalidCredentialsExchangeStrategyDueToMissingCustomType = `[ 230 { 231 "type": "wrongType", 232 "customType": "ns:credential-exchange:v1", 233 "customDescription": "foo bar" 234 } 235 ]` 236 invalidCredentialsExchangeStrategyDueToInvalidLenOfCustomDescription = `[ 237 { 238 "type": "custom", 239 "customType": "ns:credential-exchange:v1", 240 "customDescription": "%s" 241 } 242 ]` 243 invalidCredentialsExchangeStrategyDueToWrongCustomType = `[ 244 { 245 "type": "custom", 246 "customType": "wrongCustomType" 247 } 248 ]` 249 invalidCredentialsExchangeStrategyDueToWrongTenantMappingCustomType = `[ 250 { 251 "type": "custom", 252 "customType": "%s.v1000" 253 } 254 ]` 255 invalidCredentialsExchangeStrategyDueToWrongCallbackURL = `[ 256 { 257 "type": "custom", 258 "callbackUrl": "wrongURL" 259 } 260 ]` 261 262 invalidAPIResourceLinksDueToMissingType = `[ 263 { 264 "url": "https://example.com/shell/discover" 265 }, 266 { 267 "type": "console", 268 "url": "%s/shell/discover/relative" 269 } 270 ]` 271 invalidAPIResourceLinksDueToWrongType = `[ 272 { 273 "type": "wrongType", 274 "url": "https://example.com/shell/discover" 275 } 276 ]` 277 invalidAPIResourceLinksDueToMissingCustomValueOfType = `[ 278 { 279 "type": "console", 280 "customType": "foo", 281 "url": "https://example.com/shell/discover" 282 } 283 ]` 284 invalidAPIResourceLinksCustomFieldDueWrongFormat = `[ 285 { 286 "type": "custom", 287 "customType": "%^&wrong:{}", 288 "url": "https://example.com/shell/discover" 289 } 290 ]` 291 validAPIResourceLinksCustomField = `[ 292 { 293 "type": "custom", 294 "customType": "name.sap.com:spec.id:v1", 295 "url": "https://example.com/shell/discover" 296 } 297 ]` 298 invalidAPIResourceLinksDueToMissingURL = `[ 299 { 300 "type": "console" 301 } 302 ]` 303 invalidAPIResourceLinksDueToWrongURL = `[ 304 { 305 "type": "console", 306 "url": "wrongURL" 307 } 308 ]` 309 310 invalidChangeLogEntriesDueToMissingVersion = `[ 311 { 312 "date": "2020-04-29", 313 "description": "lorem ipsum dolor sit amet", 314 "releaseStatus": "active", 315 "url": "https://example.com/changelog/v1" 316 } 317 ]` 318 invalidChangeLogEntriesDueToWrongVersion = `[ 319 { 320 "date": "2020-04-29", 321 "description": "lorem ipsum dolor sit amet", 322 "releaseStatus": "active", 323 "url": "https://example.com/changelog/v1", 324 "version": "wrongValue" 325 } 326 ]` 327 invalidChangeLogEntriesDueToMissingReleaseStatus = `[ 328 { 329 "date": "2020-04-29", 330 "description": "lorem ipsum dolor sit amet", 331 "url": "https://example.com/changelog/v1", 332 "version": "1.0.0" 333 } 334 ]` 335 invalidChangeLogEntriesDueToWrongReleaseStatus = `[ 336 { 337 "date": "2020-04-29", 338 "description": "lorem ipsum dolor sit amet", 339 "releaseStatus": "wrongValue", 340 "url": "https://example.com/changelog/v1", 341 "version": "1.0.0" 342 } 343 ]` 344 invalidChangeLogEntriesDueToMissingDate = `[ 345 { 346 "description": "lorem ipsum dolor sit amet", 347 "releaseStatus": "active", 348 "url": "https://example.com/changelog/v1", 349 "version": "1.0.0" 350 } 351 ]` 352 invalidChangeLogEntriesDueToWrongDate = `[ 353 { 354 "date": "0000-00-00", 355 "description": "lorem ipsum dolor sit amet", 356 "releaseStatus": "active", 357 "url": "https://example.com/changelog/v1", 358 "version": "1.0.0" 359 } 360 ]` 361 invalidChangeLogEntriesDueToWrongURL = `[ 362 { 363 "date": "2020-04-29", 364 "description": "lorem ipsum dolor sit amet", 365 "releaseStatus": "active", 366 "url": "wrongValue", 367 "version": "1.0.0" 368 } 369 ]` 370 invalidChangeLogEntriesDueToInvalidLengthOfDescription = `[ 371 { 372 "date": "2020-04-29", 373 "description": "%s", 374 "releaseStatus": "active", 375 "url": "https://example.com/changelog/v1", 376 "version": "1.0.0" 377 } 378 ]` 379 validNamespace = `foo.bar.baz` 380 invalidNamespace = `.foo.bar.baz` 381 382 invalidCorrelationIDsElement = `["foo.bar.baz:123456", "wrongID"]` 383 invalidCorrelationIDsNonStringElement = `["foo.bar.baz:123456", 992]` 384 385 invalidEntryPointURI = `["invalidUrl"]` 386 invalidEntryPointsDueToDuplicates = `["/test/v1", "/test/v1"]` 387 invalidEntryPointsNonStringElement = `["/test/v1", 992]` 388 389 invalidExtensibleDueToInvalidJSON = `{invalid}` 390 invalidExtensibleDueToInvalidSupportedType = `{"supported":true}` 391 invalidExtensibleDueToNoSupportedProperty = `{"description":"Please find the extensibility documentation"}` 392 invalidExtensibleDueToInvalidSupportedValue = `{"supported":"invalid"}` 393 invalidExtensibleDueToSupportedAutomaticAndNoDescriptionProperty = `{"supported":"automatic"}` 394 invalidExtensibleDueToSupportedManualAndNoDescriptionProperty = `{"supported":"manual"}` 395 invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength = `{"supported":"%s", "description": "%s"}` 396 397 invalidDescriptionFieldWithExceedingMaxLength = strings.Repeat("a", maxDescriptionLength+1) 398 ) 399 400 func TestConfig_ValidateConfig(t *testing.T) { 401 var tests = []struct { 402 Name string 403 ConfigProvider func() ord.WellKnownConfig 404 BaseURL string 405 ExpectedToBeValid bool 406 }{ 407 { 408 Name: "Invalid 'baseURL' field for config", 409 ConfigProvider: func() ord.WellKnownConfig { 410 config := fixWellKnownConfig() 411 config.BaseURL = baseURL + "/full/path" 412 return *config 413 }, 414 }, 415 { 416 Name: "Missing 'OpenResourceDiscoveryV1' field for config", 417 ConfigProvider: func() ord.WellKnownConfig { 418 config := fixWellKnownConfig() 419 config.OpenResourceDiscoveryV1 = ord.OpenResourceDiscoveryV1{} 420 return *config 421 }, 422 }, 423 { 424 Name: "Missing 'url' field for document for config", 425 ConfigProvider: func() ord.WellKnownConfig { 426 config := fixWellKnownConfig() 427 config.OpenResourceDiscoveryV1.Documents[0].URL = "" 428 return *config 429 }, 430 }, 431 { 432 Name: "Missing 'accessStrategies' field for document for config", 433 ConfigProvider: func() ord.WellKnownConfig { 434 config := fixWellKnownConfig() 435 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies = nil 436 return *config 437 }, 438 }, 439 { 440 Name: "Missing 'type' field for 'accessStrategies' field of document for config", 441 ConfigProvider: func() ord.WellKnownConfig { 442 config := fixWellKnownConfig() 443 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].Type = "" 444 return *config 445 }, 446 }, 447 { 448 Name: "Invalid field `type` for `accessStrategies` field of document for config", 449 ConfigProvider: func() ord.WellKnownConfig { 450 config := fixWellKnownConfig() 451 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].Type = invalidType 452 return *config 453 }, 454 }, 455 { 456 Name: "Invalid field `customType` when field `type` is not `custom` for `accessStrategies` field of document for config", 457 ConfigProvider: func() ord.WellKnownConfig { 458 config := fixWellKnownConfig() 459 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].Type = accessstrategy.OpenAccessStrategy 460 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].CustomType = "foo" 461 462 return *config 463 }, 464 }, 465 { 466 Name: "Invalid field `customType` when field `type` is `custom` for `accessStrategies` field of document for config", 467 ConfigProvider: func() ord.WellKnownConfig { 468 config := fixWellKnownConfig() 469 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].Type = accessstrategy.CustomAccessStrategy 470 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].CustomType = invalidCustomType 471 472 return *config 473 }, 474 }, 475 { 476 Name: "Field `type` is not `custom` when `customType` is valid for `accessStrategies` field of document for config", 477 ConfigProvider: func() ord.WellKnownConfig { 478 config := fixWellKnownConfig() 479 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].Type = accessstrategy.OpenAccessStrategy 480 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].CustomType = "sap:custom-definition-format:v1" 481 482 return *config 483 }, 484 }, 485 { 486 Name: "Invalid field `customDescription` when field `type` is not `custom` for `accessStrategies` field of document for config", 487 ConfigProvider: func() ord.WellKnownConfig { 488 config := fixWellKnownConfig() 489 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].Type = accessstrategy.OpenAccessStrategy 490 config.OpenResourceDiscoveryV1.Documents[0].AccessStrategies[0].CustomDescription = "foo" 491 492 return *config 493 }, 494 }, 495 { 496 Name: "Invalid when webhookURL is not /well-known, no config baseURL is set => empty baseURL and documents have relative URLs", 497 ConfigProvider: func() ord.WellKnownConfig { 498 config := fixWellKnownConfig() 499 config.BaseURL = "" 500 501 return *config 502 }, 503 BaseURL: "", 504 }, 505 } 506 507 for _, test := range tests { 508 t.Run(test.Name, func(t *testing.T) { 509 cfg := test.ConfigProvider() 510 err := cfg.Validate(test.BaseURL) 511 if test.ExpectedToBeValid { 512 require.NoError(t, err) 513 } else { 514 require.Error(t, err) 515 } 516 }) 517 } 518 } 519 520 func TestDocuments_ValidateSystemInstance(t *testing.T) { 521 var tests = []struct { 522 Name string 523 DocumentProvider func() []*ord.Document 524 CalculatedBaseURL *string 525 ExpectedToBeValid bool 526 }{ 527 { 528 Name: "Invalid value for `correlationIds` field for SystemInstance", 529 DocumentProvider: func() []*ord.Document { 530 doc := fixORDDocument() 531 doc.DescribedSystemInstance.CorrelationIDs = json.RawMessage(invalidCorrelationIDsElement) 532 533 return []*ord.Document{doc} 534 }, 535 }, { 536 Name: "Invalid `correlationIds` field when it is invalid JSON for SystemInstance", 537 DocumentProvider: func() []*ord.Document { 538 doc := fixORDDocument() 539 doc.DescribedSystemInstance.CorrelationIDs = json.RawMessage(invalidJSON) 540 541 return []*ord.Document{doc} 542 }, 543 }, { 544 Name: "Invalid `correlationIds` field when it isn't a JSON array for SystemInstance", 545 DocumentProvider: func() []*ord.Document { 546 doc := fixORDDocument() 547 doc.DescribedSystemInstance.CorrelationIDs = json.RawMessage("{}") 548 549 return []*ord.Document{doc} 550 }, 551 }, { 552 Name: "Valid `correlationIds` field when the JSON array is empty for SystemInstance", 553 DocumentProvider: func() []*ord.Document { 554 doc := fixORDDocument() 555 doc.DescribedSystemInstance.CorrelationIDs = json.RawMessage("[]") 556 557 return []*ord.Document{doc} 558 }, 559 ExpectedToBeValid: true, 560 }, { 561 Name: "Invalid `correlationIds` field when it contains non string value for SystemInstance", 562 DocumentProvider: func() []*ord.Document { 563 doc := fixORDDocument() 564 doc.DescribedSystemInstance.CorrelationIDs = json.RawMessage(invalidCorrelationIDsNonStringElement) 565 566 return []*ord.Document{doc} 567 }, 568 }, { 569 Name: "Invalid `baseUrl` for SystemInstance", 570 DocumentProvider: func() []*ord.Document { 571 doc := fixORDDocument() 572 doc.DescribedSystemInstance.BaseURL = str.Ptr("http://test.com/test/v1") 573 574 return []*ord.Document{doc} 575 }, 576 }, { 577 Name: "`baseUrl` of `DescribedSystemInstance` does not match the calculated baseURL", 578 DocumentProvider: func() []*ord.Document { 579 doc := fixORDDocument() 580 doc.DescribedSystemInstance.BaseURL = str.Ptr(baseURL2) 581 582 return []*ord.Document{doc} 583 }, 584 }, { 585 Name: "No `baseUrl` of `DescribedSystemInstance` is provided when the calculated baseURL is empty", 586 DocumentProvider: func() []*ord.Document { 587 doc := fixORDDocument() 588 doc.DescribedSystemInstance = nil 589 590 return []*ord.Document{doc} 591 }, 592 CalculatedBaseURL: str.Ptr(""), 593 }, { 594 Name: "`baseUrl` of `DescribedSystemInstance` is different for each document when the calculated baseURL is empty", 595 DocumentProvider: func() []*ord.Document { 596 doc := fixORDDocument() 597 doc2 := fixORDDocument() 598 doc2.DescribedSystemInstance.BaseURL = str.Ptr(baseURL2) 599 600 return []*ord.Document{doc, doc2} 601 }, 602 CalculatedBaseURL: str.Ptr(""), 603 }, { 604 Name: "Invalid JSON `Labels` field for SystemInstance", 605 DocumentProvider: func() []*ord.Document { 606 doc := fixORDDocument() 607 doc.DescribedSystemInstance.OrdLabels = json.RawMessage(invalidJSON) 608 609 return []*ord.Document{doc} 610 }, 611 }, { 612 Name: "Invalid JSON object `Labels` field for SystemInstance", 613 DocumentProvider: func() []*ord.Document { 614 doc := fixORDDocument() 615 doc.DescribedSystemInstance.OrdLabels = json.RawMessage(`[]`) 616 617 return []*ord.Document{doc} 618 }, 619 }, { 620 Name: "`Labels` values are not array for SystemInstance", 621 DocumentProvider: func() []*ord.Document { 622 doc := fixORDDocument() 623 doc.DescribedSystemInstance.OrdLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 624 625 return []*ord.Document{doc} 626 }, 627 }, { 628 Name: "`Labels` values are not array of strings for SystemInstance", 629 DocumentProvider: func() []*ord.Document { 630 doc := fixORDDocument() 631 doc.DescribedSystemInstance.OrdLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 632 633 return []*ord.Document{doc} 634 }, 635 }, { 636 Name: "Invalid key for JSON `Labels` field for SystemInstance", 637 DocumentProvider: func() []*ord.Document { 638 doc := fixORDDocument() 639 doc.DescribedSystemInstance.OrdLabels = json.RawMessage(invalidLabelsWhenKeyIsWrong) 640 641 return []*ord.Document{doc} 642 }, 643 }, { 644 Name: "Invalid JSON `DocumentationLabels` field for SystemInstance", 645 DocumentProvider: func() []*ord.Document { 646 doc := fixORDDocument() 647 doc.DescribedSystemInstance.DocumentationLabels = json.RawMessage(invalidJSON) 648 649 return []*ord.Document{doc} 650 }, 651 }, { 652 Name: "Invalid JSON object `DocumentationLabels` field for SystemInstance", 653 DocumentProvider: func() []*ord.Document { 654 doc := fixORDDocument() 655 doc.DescribedSystemInstance.DocumentationLabels = json.RawMessage(`[]`) 656 657 return []*ord.Document{doc} 658 }, 659 }, { 660 Name: "`DocumentationLabels` values are not array for SystemInstance", 661 DocumentProvider: func() []*ord.Document { 662 doc := fixORDDocument() 663 doc.DescribedSystemInstance.DocumentationLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 664 665 return []*ord.Document{doc} 666 }, 667 }, { 668 Name: "`DocumentationLabels` values are not array of strings for SystemInstance", 669 DocumentProvider: func() []*ord.Document { 670 doc := fixORDDocument() 671 doc.DescribedSystemInstance.DocumentationLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 672 673 return []*ord.Document{doc} 674 }, 675 }, { 676 Name: "Invalid `tags` field element for SystemInstance", 677 DocumentProvider: func() []*ord.Document { 678 doc := fixORDDocument() 679 doc.DescribedSystemInstance.Tags = json.RawMessage(invalidTagsValue) 680 681 return []*ord.Document{doc} 682 }, 683 }, { 684 Name: "Invalid `tags` field when it is invalid JSON for SystemInstance", 685 DocumentProvider: func() []*ord.Document { 686 doc := fixORDDocument() 687 doc.DescribedSystemInstance.Tags = json.RawMessage(invalidJSON) 688 689 return []*ord.Document{doc} 690 }, 691 }, { 692 Name: "Invalid `tags` field when it isn't a JSON array for SystemInstance", 693 DocumentProvider: func() []*ord.Document { 694 doc := fixORDDocument() 695 doc.DescribedSystemInstance.Tags = json.RawMessage("{}") 696 697 return []*ord.Document{doc} 698 }, 699 }, { 700 Name: "Valid `tags` field when the JSON array is empty", 701 DocumentProvider: func() []*ord.Document { 702 doc := fixORDDocument() 703 doc.DescribedSystemInstance.Tags = json.RawMessage("[]") 704 705 return []*ord.Document{doc} 706 }, 707 ExpectedToBeValid: true, 708 }, { 709 Name: "Invalid `tags` field when it contains non string value", 710 DocumentProvider: func() []*ord.Document { 711 doc := fixORDDocument() 712 doc.DescribedSystemInstance.Tags = json.RawMessage(invalidTagsValueIntegerElement) 713 714 return []*ord.Document{doc} 715 }, 716 }, { 717 Name: "`ApplicationNamespace` values are not valid", 718 DocumentProvider: func() []*ord.Document { 719 doc := fixORDDocument() 720 doc.DescribedSystemInstance.ApplicationNamespace = str.Ptr(invalidNamespace) 721 722 return []*ord.Document{doc} 723 }, 724 }, { 725 Name: "`ApplicationNamespace` values are valid", 726 DocumentProvider: func() []*ord.Document { 727 doc := fixORDDocument() 728 doc.DescribedSystemInstance.ApplicationNamespace = str.Ptr(validNamespace) 729 730 return []*ord.Document{doc} 731 }, 732 ExpectedToBeValid: true, 733 }, { 734 Name: "Valid missing `localTenantID` field for SystemInstance", 735 DocumentProvider: func() []*ord.Document { 736 doc := fixORDDocument() 737 doc.ConsumptionBundles[0].LocalTenantID = nil 738 739 return []*ord.Document{doc} 740 }, 741 ExpectedToBeValid: true, 742 }, 743 { 744 Name: "Exceeded length of `localTenantID` field for SystemInstance", 745 DocumentProvider: func() []*ord.Document { 746 doc := fixORDDocument() 747 doc.ConsumptionBundles[0].LocalTenantID = str.Ptr(strings.Repeat("a", invalidLocalTenantIDLength)) 748 749 return []*ord.Document{doc} 750 }, 751 }, 752 { 753 Name: "Invalid empty `localTenantID` field for SystemInstance", 754 DocumentProvider: func() []*ord.Document { 755 doc := fixORDDocument() 756 doc.ConsumptionBundles[0].LocalTenantID = str.Ptr("") 757 758 return []*ord.Document{doc} 759 }, 760 }, 761 } 762 763 for _, test := range tests { 764 t.Run(test.Name, func(t *testing.T) { 765 var docs ord.Documents 766 if len(test.DocumentProvider()) == 0 { 767 docs = ord.Documents{test.DocumentProvider()[0]} 768 } else { 769 docs = test.DocumentProvider() 770 } 771 772 var url string 773 if test.CalculatedBaseURL != nil { 774 url = *test.CalculatedBaseURL 775 } else { 776 url = baseURL 777 } 778 779 resourcesFromDB := ord.ResourcesFromDB{ 780 APIs: apisFromDB, 781 Events: eventsFromDB, 782 Packages: pkgsFromDB, 783 Bundles: bndlsFromDB, 784 } 785 err := docs.Validate(url, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 786 if test.ExpectedToBeValid { 787 require.NoError(t, err) 788 } else { 789 require.Error(t, err) 790 } 791 }) 792 } 793 } 794 795 func TestDocuments_ValidateDocument(t *testing.T) { 796 var tests = []struct { 797 Name string 798 DocumentProvider func() []*ord.Document 799 ExpectedToBeValid bool 800 }{ 801 { 802 Name: "Missing `OpenResourceDiscovery` field for Document", 803 DocumentProvider: func() []*ord.Document { 804 doc := fixORDDocument() 805 doc.OpenResourceDiscovery = "" 806 807 return []*ord.Document{doc} 808 }, 809 }, { 810 Name: "Invalid `OpenResourceDiscovery` field for Document", 811 DocumentProvider: func() []*ord.Document { 812 doc := fixORDDocument() 813 doc.OpenResourceDiscovery = "wrongValue" 814 815 return []*ord.Document{doc} 816 }, 817 }, 818 { 819 Name: "Only major version is checked for `OpenResourceDiscovery` field for Document", 820 DocumentProvider: func() []*ord.Document { 821 doc := fixORDDocument() 822 doc.OpenResourceDiscovery = "1.4" 823 824 return []*ord.Document{doc} 825 }, 826 ExpectedToBeValid: true, 827 }, 828 } 829 830 for _, test := range tests { 831 t.Run(test.Name, func(t *testing.T) { 832 docs := ord.Documents{test.DocumentProvider()[0]} 833 resourcesFromDB := ord.ResourcesFromDB{ 834 APIs: apisFromDB, 835 Events: eventsFromDB, 836 Packages: pkgsFromDB, 837 Bundles: bndlsFromDB, 838 } 839 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 840 if test.ExpectedToBeValid { 841 require.NoError(t, err) 842 } else { 843 require.Error(t, err) 844 } 845 }) 846 } 847 } 848 849 func TestDocuments_ValidatePackage(t *testing.T) { 850 var tests = []struct { 851 Name string 852 DocumentProvider func() []*ord.Document 853 ExpectedToBeValid bool 854 AfterTest func() 855 }{ 856 { 857 Name: "Valid document", 858 DocumentProvider: func() []*ord.Document { 859 return []*ord.Document{fixORDDocument()} 860 }, 861 ExpectedToBeValid: true, 862 }, { 863 Name: "Missing `openResourceDiscovery` field for a Document", 864 DocumentProvider: func() []*ord.Document { 865 doc := fixORDDocument() 866 doc.OpenResourceDiscovery = "" 867 868 return []*ord.Document{doc} 869 }, 870 }, { 871 Name: "Invalid `openResourceDiscovery` field for a Document", 872 DocumentProvider: func() []*ord.Document { 873 doc := fixORDDocument() 874 doc.OpenResourceDiscovery = invalidOpenResourceDiscovery 875 876 return []*ord.Document{doc} 877 }, 878 }, { 879 Name: "Invalid `baseUrl` of describedSystemInstance Document field", 880 DocumentProvider: func() []*ord.Document { 881 doc := fixORDDocument() 882 doc.DescribedSystemInstance.BaseURL = str.Ptr(invalidURL) 883 884 return []*ord.Document{doc} 885 }, 886 }, { 887 Name: "Missing `ordID` field for Package", 888 DocumentProvider: func() []*ord.Document { 889 doc := fixORDDocument() 890 doc.Packages[0].OrdID = "" 891 892 return []*ord.Document{doc} 893 }, 894 }, { 895 Name: "Invalid `ordID` field for Package", 896 DocumentProvider: func() []*ord.Document { 897 doc := fixORDDocument() 898 doc.Packages[0].OrdID = invalidOrdID 899 900 return []*ord.Document{doc} 901 }, 902 }, { 903 Name: "Missing `title` field for Package", 904 DocumentProvider: func() []*ord.Document { 905 doc := fixORDDocument() 906 doc.Packages[0].Title = "" 907 908 return []*ord.Document{doc} 909 }, 910 }, { 911 Name: "Exceeded length of `title ` field for Package", 912 DocumentProvider: func() []*ord.Document { 913 doc := fixORDDocument() 914 doc.Packages[0].Title = strings.Repeat("a", invalidTitleLength) 915 916 return []*ord.Document{doc} 917 }, 918 }, { 919 Name: "Missing `shortDescription` field for Package", 920 DocumentProvider: func() []*ord.Document { 921 doc := fixORDDocument() 922 doc.Packages[0].ShortDescription = "" 923 924 return []*ord.Document{doc} 925 }, 926 }, { 927 Name: "Exceeded length of `shortDescription` field for Package", 928 DocumentProvider: func() []*ord.Document { 929 doc := fixORDDocument() 930 doc.Packages[0].ShortDescription = strings.Repeat("a", invalidShortDescriptionLength) 931 932 return []*ord.Document{doc} 933 }, 934 }, { 935 Name: "Invalid empty `shortDescription` field for Package", 936 DocumentProvider: func() []*ord.Document { 937 doc := fixORDDocument() 938 doc.Packages[0].ShortDescription = "" 939 940 return []*ord.Document{doc} 941 }, 942 }, { 943 Name: "New lines in `shortDescription` field for Package", 944 DocumentProvider: func() []*ord.Document { 945 doc := fixORDDocument() 946 doc.Packages[0].ShortDescription = `newLine\n` 947 948 return []*ord.Document{doc} 949 }, 950 }, { 951 Name: "Missing `description` filed for Package", 952 DocumentProvider: func() []*ord.Document { 953 doc := fixORDDocument() 954 doc.Packages[0].Description = "" 955 956 return []*ord.Document{doc} 957 }, 958 }, { 959 Name: "Exceeded length of `description` field for Package", 960 DocumentProvider: func() []*ord.Document { 961 doc := fixORDDocument() 962 doc.Packages[0].Description = invalidDescriptionFieldWithExceedingMaxLength 963 964 return []*ord.Document{doc} 965 }, 966 }, { 967 Name: "Missing `version` field for Package", 968 DocumentProvider: func() []*ord.Document { 969 doc := fixORDDocument() 970 doc.Packages[0].Version = "" 971 972 return []*ord.Document{doc} 973 }, 974 }, { 975 Name: "Invalid `version` field for Package", 976 DocumentProvider: func() []*ord.Document { 977 doc := fixORDDocument() 978 doc.Packages[0].Version = invalidVersion 979 980 return []*ord.Document{doc} 981 }, 982 }, 983 { 984 Name: "Not incremented `version` field when Package has been changed", 985 DocumentProvider: func() []*ord.Document { 986 doc := fixORDDocument() 987 doc.Packages[0].Industry = json.RawMessage(`["Mining"]`) 988 989 newHash, err := ord.HashObject(doc.Packages[0]) 990 require.NoError(t, err) 991 992 resourceHashes[packageORDID] = newHash 993 994 return []*ord.Document{doc} 995 }, 996 AfterTest: func() { 997 resourceHashes = fixResourceHashes() 998 }, 999 }, 1000 { 1001 Name: "Valid incremented `version` field when package has changed", 1002 DocumentProvider: func() []*ord.Document { 1003 doc := fixORDDocument() 1004 doc.Packages[0].Industry = json.RawMessage(`["Utilities"]`) 1005 doc.Packages[0].Version = "2.1.4" 1006 1007 hash, err := ord.HashObject(doc.Packages[0]) 1008 require.NoError(t, err) 1009 1010 resourceHashes[packageORDID] = hash 1011 1012 return []*ord.Document{doc} 1013 }, 1014 AfterTest: func() { 1015 resourceHashes = fixResourceHashes() 1016 }, 1017 ExpectedToBeValid: true, 1018 }, 1019 { 1020 Name: "Missing `policyLevel` field for Package", 1021 DocumentProvider: func() []*ord.Document { 1022 doc := fixORDDocument() 1023 doc.Packages[0].PolicyLevel = "" 1024 1025 return []*ord.Document{doc} 1026 }, 1027 }, { 1028 Name: "Invalid `policyLevel` field for Package", 1029 DocumentProvider: func() []*ord.Document { 1030 doc := fixORDDocument() 1031 doc.Packages[0].PolicyLevel = invalidPolicyLevel 1032 1033 return []*ord.Document{doc} 1034 }, 1035 }, { 1036 Name: "`policyLevel` field for Package is not of type `custom` when `customPolicyLevel` is set", 1037 DocumentProvider: func() []*ord.Document { 1038 doc := fixORDDocument() 1039 doc.Packages[0].CustomPolicyLevel = str.Ptr("myCustomPolicyLevel") 1040 doc.Packages[0].PolicyLevel = policyLevel 1041 1042 return []*ord.Document{doc} 1043 }, 1044 }, { 1045 Name: "Invalid `CustomPolicyLevel` field value for Package when `PolicyLevel` is set to `custom`", 1046 DocumentProvider: func() []*ord.Document { 1047 doc := fixORDDocument() 1048 doc.Packages[0].CustomPolicyLevel = str.Ptr("invalid-value") 1049 doc.Packages[0].PolicyLevel = "custom" 1050 1051 return []*ord.Document{doc} 1052 }, 1053 }, 1054 { 1055 Name: "Missing `type` from `PackageLinks` for Package", 1056 DocumentProvider: func() []*ord.Document { 1057 doc := fixORDDocument() 1058 doc.Packages[0].PackageLinks = json.RawMessage(invalidPackageLinkDueToMissingType) 1059 1060 return []*ord.Document{doc} 1061 }, 1062 }, { 1063 Name: "Invalid `type` key in `PackageLinks` for Package", 1064 DocumentProvider: func() []*ord.Document { 1065 doc := fixORDDocument() 1066 doc.Packages[0].PackageLinks = json.RawMessage(invalidPackageLinkDueToWrongType) 1067 1068 return []*ord.Document{doc} 1069 }, 1070 }, { 1071 Name: "Missing `url` from `PackageLinks` for Package", 1072 DocumentProvider: func() []*ord.Document { 1073 doc := fixORDDocument() 1074 doc.Packages[0].PackageLinks = json.RawMessage(invalidPackageLinkDueToMissingURL) 1075 1076 return []*ord.Document{doc} 1077 }, 1078 }, { 1079 Name: "Invalid `url` key in `PackageLinks` for Package", 1080 DocumentProvider: func() []*ord.Document { 1081 doc := fixORDDocument() 1082 doc.Packages[0].PackageLinks = json.RawMessage(invalidPackageLinkDueToWrongURL) 1083 1084 return []*ord.Document{doc} 1085 }, 1086 }, { 1087 Name: "Invalid `customType` key in `PackageLinks` for Package", 1088 DocumentProvider: func() []*ord.Document { 1089 doc := fixORDDocument() 1090 doc.Packages[0].PackageLinks = json.RawMessage(invalidPackageLinkDueToWrongFormatOfCustomType) 1091 1092 return []*ord.Document{doc} 1093 }, 1094 }, { 1095 Name: "Valid `customType` key in `PackageLinks` for Package", 1096 DocumentProvider: func() []*ord.Document { 1097 doc := fixORDDocument() 1098 doc.Packages[0].PackageLinks = json.RawMessage(validPackageLinkCorrectFormatOfCustomType) 1099 1100 return []*ord.Document{doc} 1101 }, 1102 ExpectedToBeValid: true, 1103 }, { 1104 Name: "Field `type` in `PackageLinks` is not set to `custom` when `customType` field is provided", 1105 DocumentProvider: func() []*ord.Document { 1106 doc := fixORDDocument() 1107 doc.Packages[0].PackageLinks = json.RawMessage(invalidPackageLinkTypeWhenProvidedCustomType) 1108 1109 return []*ord.Document{doc} 1110 }, 1111 }, { 1112 Name: "Invalid `type` set to `custom` in `PackageLinks` when `customType` field is not provided", 1113 DocumentProvider: func() []*ord.Document { 1114 doc := fixORDDocument() 1115 doc.Packages[0].PackageLinks = json.RawMessage(invalidPackageLinkCustomTypeWhenCustomTypeNotProvided) 1116 1117 return []*ord.Document{doc} 1118 }, 1119 }, { 1120 Name: "Invalid `PackageLinks` field when it is invalid JSON for Package", 1121 DocumentProvider: func() []*ord.Document { 1122 doc := fixORDDocument() 1123 doc.Packages[0].PackageLinks = json.RawMessage(invalidJSON) 1124 1125 return []*ord.Document{doc} 1126 }, 1127 }, { 1128 Name: "Invalid `PackageLinks` field when it isn't a JSON array for Package", 1129 DocumentProvider: func() []*ord.Document { 1130 doc := fixORDDocument() 1131 doc.Packages[0].PackageLinks = json.RawMessage("{}") 1132 1133 return []*ord.Document{doc} 1134 }, 1135 }, { 1136 Name: "Valid `PackageLinks` field when it is an empty JSON array for Package", 1137 DocumentProvider: func() []*ord.Document { 1138 doc := fixORDDocument() 1139 doc.Packages[0].PackageLinks = json.RawMessage("[]") 1140 1141 return []*ord.Document{doc} 1142 }, 1143 ExpectedToBeValid: true, 1144 }, { 1145 Name: "Missing `title` field in `Links` for Package", 1146 DocumentProvider: func() []*ord.Document { 1147 doc := fixORDDocument() 1148 doc.Packages[0].Links = json.RawMessage(invalidLinkDueToMissingTitle) 1149 1150 return []*ord.Document{doc} 1151 }, 1152 }, { 1153 Name: "Missing `url` field in `Links` for Package", 1154 DocumentProvider: func() []*ord.Document { 1155 doc := fixORDDocument() 1156 doc.Packages[0].Links = json.RawMessage(invalidLinkDueToMissingURL) 1157 1158 return []*ord.Document{doc} 1159 }, 1160 }, { 1161 Name: "Invalid `links` field when it is invalid JSON for Package", 1162 DocumentProvider: func() []*ord.Document { 1163 doc := fixORDDocument() 1164 doc.Packages[0].Links = json.RawMessage(invalidJSON) 1165 1166 return []*ord.Document{doc} 1167 }, 1168 }, { 1169 Name: "Invalid `links` field when it isn't a JSON array for Package", 1170 DocumentProvider: func() []*ord.Document { 1171 doc := fixORDDocument() 1172 doc.Packages[0].Links = json.RawMessage("{}") 1173 1174 return []*ord.Document{doc} 1175 }, 1176 }, { 1177 Name: "Valid `links` field when it is an empty JSON array for Package", 1178 DocumentProvider: func() []*ord.Document { 1179 doc := fixORDDocument() 1180 doc.Packages[0].Links = json.RawMessage("[]") 1181 1182 return []*ord.Document{doc} 1183 }, 1184 ExpectedToBeValid: true, 1185 }, { 1186 Name: "Invalid `url` field in `Links` for Package", 1187 DocumentProvider: func() []*ord.Document { 1188 doc := fixORDDocument() 1189 doc.Packages[0].Links = json.RawMessage(invalidLinkDueToWrongURL) 1190 1191 return []*ord.Document{doc} 1192 }, 1193 }, { 1194 Name: "Invalid `description` field with exceeding length in `Links` for Package", 1195 DocumentProvider: func() []*ord.Document { 1196 doc := fixORDDocument() 1197 doc.Packages[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, invalidDescriptionFieldWithExceedingMaxLength)) 1198 1199 return []*ord.Document{doc} 1200 }, 1201 }, { 1202 Name: "Invalid empty `description` field in `Links` for Package", 1203 DocumentProvider: func() []*ord.Document { 1204 doc := fixORDDocument() 1205 doc.Packages[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, "")) 1206 1207 return []*ord.Document{doc} 1208 }, 1209 }, { 1210 Name: "Missing `vendor` field for Package", 1211 DocumentProvider: func() []*ord.Document { 1212 doc := fixORDDocument() 1213 doc.Packages[0].Vendor = nil 1214 1215 return []*ord.Document{doc} 1216 }, 1217 }, { 1218 Name: "Invalid `vendor` field for Package", 1219 DocumentProvider: func() []*ord.Document { 1220 doc := fixORDDocument() 1221 doc.Packages[0].Vendor = str.Ptr(invalidVendor) 1222 1223 return []*ord.Document{doc} 1224 }, 1225 }, { 1226 Name: "Invalid `vendor` field for Package when `policyLevel` is sap-partner", 1227 DocumentProvider: func() []*ord.Document { 1228 doc := fixORDDocument() 1229 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 1230 doc.Packages[0].Vendor = str.Ptr(ord.SapVendor) 1231 1232 return []*ord.Document{doc} 1233 }, 1234 }, { 1235 Name: "Invalid `vendor` field for Package when `policyLevel` is sap", 1236 DocumentProvider: func() []*ord.Document { 1237 doc := fixORDDocument() 1238 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 1239 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 1240 1241 return []*ord.Document{doc} 1242 }, 1243 }, { 1244 Name: "Missing `partOfProducts` field for Package", 1245 DocumentProvider: func() []*ord.Document { 1246 doc := fixORDDocument() 1247 doc.Packages[0].PartOfProducts = nil 1248 1249 return []*ord.Document{doc} 1250 }, 1251 }, { 1252 Name: "Valid `partOfProducts` field when the JSON array is empty", 1253 DocumentProvider: func() []*ord.Document { 1254 doc := fixORDDocument() 1255 doc.Packages[0].PartOfProducts = json.RawMessage("[]") 1256 1257 return []*ord.Document{doc} 1258 }, 1259 ExpectedToBeValid: true, 1260 }, { 1261 Name: "Invalid element of `partOfProducts` array field for Package", 1262 DocumentProvider: func() []*ord.Document { 1263 doc := fixORDDocument() 1264 doc.Packages[0].PartOfProducts = json.RawMessage(invalidPartOfProductsElement) 1265 1266 return []*ord.Document{doc} 1267 }, 1268 }, { 1269 Name: "Invalid `partOfProducts` field when it is invalid JSON for Package", 1270 DocumentProvider: func() []*ord.Document { 1271 doc := fixORDDocument() 1272 doc.Packages[0].PartOfProducts = json.RawMessage(invalidJSON) 1273 1274 return []*ord.Document{doc} 1275 }, 1276 }, { 1277 Name: "Invalid `partOfProducts` field when it isn't a JSON array for Package", 1278 DocumentProvider: func() []*ord.Document { 1279 doc := fixORDDocument() 1280 doc.Packages[0].PartOfProducts = json.RawMessage("{}") 1281 1282 return []*ord.Document{doc} 1283 }, 1284 }, { 1285 Name: "Invalid `partOfProducts` field when it contains non string value", 1286 DocumentProvider: func() []*ord.Document { 1287 doc := fixORDDocument() 1288 doc.Packages[0].PartOfProducts = json.RawMessage(invalidPartOfProductsIntegerElement) 1289 1290 return []*ord.Document{doc} 1291 }, 1292 }, { 1293 Name: "Invalid `tags` field element for Package", 1294 DocumentProvider: func() []*ord.Document { 1295 doc := fixORDDocument() 1296 doc.Packages[0].Tags = json.RawMessage(invalidTagsValue) 1297 1298 return []*ord.Document{doc} 1299 }, 1300 }, { 1301 Name: "Invalid `tags` field when it is invalid JSON for Package", 1302 DocumentProvider: func() []*ord.Document { 1303 doc := fixORDDocument() 1304 doc.Packages[0].Tags = json.RawMessage(invalidJSON) 1305 1306 return []*ord.Document{doc} 1307 }, 1308 }, { 1309 Name: "Invalid `tags` field when it isn't a JSON array for Package", 1310 DocumentProvider: func() []*ord.Document { 1311 doc := fixORDDocument() 1312 doc.Packages[0].Tags = json.RawMessage("{}") 1313 1314 return []*ord.Document{doc} 1315 }, 1316 }, { 1317 Name: "Valid `tags` field when the JSON array is empty", 1318 DocumentProvider: func() []*ord.Document { 1319 doc := fixORDDocument() 1320 doc.Packages[0].Tags = json.RawMessage("[]") 1321 1322 return []*ord.Document{doc} 1323 }, 1324 ExpectedToBeValid: true, 1325 }, { 1326 Name: "Invalid `tags` field when it contains non string value", 1327 DocumentProvider: func() []*ord.Document { 1328 doc := fixORDDocument() 1329 doc.Packages[0].Tags = json.RawMessage(invalidTagsValueIntegerElement) 1330 1331 return []*ord.Document{doc} 1332 }, 1333 }, { 1334 Name: "Invalid JSON `Labels` field for Package", 1335 DocumentProvider: func() []*ord.Document { 1336 doc := fixORDDocument() 1337 doc.Packages[0].Labels = json.RawMessage(invalidJSON) 1338 1339 return []*ord.Document{doc} 1340 }, 1341 }, { 1342 Name: "Invalid JSON object `Labels` field for Package", 1343 DocumentProvider: func() []*ord.Document { 1344 doc := fixORDDocument() 1345 doc.Packages[0].Labels = json.RawMessage(`[]`) 1346 1347 return []*ord.Document{doc} 1348 }, 1349 }, { 1350 Name: "`Labels` values are not array for Package", 1351 DocumentProvider: func() []*ord.Document { 1352 doc := fixORDDocument() 1353 doc.Packages[0].Labels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 1354 1355 return []*ord.Document{doc} 1356 }, 1357 }, { 1358 Name: "`Labels` values are not array of strings for Package", 1359 DocumentProvider: func() []*ord.Document { 1360 doc := fixORDDocument() 1361 doc.Packages[0].Labels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 1362 1363 return []*ord.Document{doc} 1364 }, 1365 }, { 1366 Name: "Invalid key for JSON `Labels` field for Package", 1367 DocumentProvider: func() []*ord.Document { 1368 doc := fixORDDocument() 1369 doc.Packages[0].Labels = json.RawMessage(invalidLabelsWhenKeyIsWrong) 1370 1371 return []*ord.Document{doc} 1372 }, 1373 }, { 1374 Name: "Invalid JSON object `DocumentationLabels` field for Package", 1375 DocumentProvider: func() []*ord.Document { 1376 doc := fixORDDocument() 1377 doc.Packages[0].DocumentationLabels = json.RawMessage(`[]`) 1378 1379 return []*ord.Document{doc} 1380 }, 1381 }, { 1382 Name: "`DocumentationLabels` values are not array for Package", 1383 DocumentProvider: func() []*ord.Document { 1384 doc := fixORDDocument() 1385 doc.Packages[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 1386 1387 return []*ord.Document{doc} 1388 }, 1389 }, { 1390 Name: "`DocumentationLabels` values are not array of strings for Package", 1391 DocumentProvider: func() []*ord.Document { 1392 doc := fixORDDocument() 1393 doc.Packages[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 1394 1395 return []*ord.Document{doc} 1396 }, 1397 }, { 1398 Name: "Invalid `countries` field element for Package", 1399 DocumentProvider: func() []*ord.Document { 1400 doc := fixORDDocument() 1401 doc.Packages[0].Countries = json.RawMessage(invalidCountriesElement) 1402 1403 return []*ord.Document{doc} 1404 }, 1405 }, { 1406 Name: "Invalid `countries` field when JSON array contains non string element for Package", 1407 DocumentProvider: func() []*ord.Document { 1408 doc := fixORDDocument() 1409 doc.Packages[0].Countries = json.RawMessage(invalidCountriesNonStringElement) 1410 1411 return []*ord.Document{doc} 1412 }, 1413 }, { 1414 Name: "Invalid `countries` field when it is invalid JSON for Package", 1415 DocumentProvider: func() []*ord.Document { 1416 doc := fixORDDocument() 1417 doc.Packages[0].Countries = json.RawMessage(invalidJSON) 1418 1419 return []*ord.Document{doc} 1420 }, 1421 }, { 1422 Name: "Invalid `countries` field when it isn't a JSON array for Package", 1423 DocumentProvider: func() []*ord.Document { 1424 doc := fixORDDocument() 1425 doc.Packages[0].Countries = json.RawMessage("{}") 1426 1427 return []*ord.Document{doc} 1428 }, 1429 }, { 1430 Name: "Valid `countries` field when the JSON array is empty", 1431 DocumentProvider: func() []*ord.Document { 1432 doc := fixORDDocument() 1433 doc.Packages[0].Countries = json.RawMessage("[]") 1434 1435 return []*ord.Document{doc} 1436 }, 1437 ExpectedToBeValid: true, 1438 }, 1439 { 1440 Name: "Invalid `lineOfBusiness` field element for Package", 1441 DocumentProvider: func() []*ord.Document { 1442 doc := fixORDDocument() 1443 doc.Packages[0].LineOfBusiness = json.RawMessage(invalidLineOfBusinessElement) 1444 1445 return []*ord.Document{doc} 1446 }, 1447 }, { 1448 Name: "Invalid `lineOfBusiness` field when JSON array contains non string element for Package", 1449 DocumentProvider: func() []*ord.Document { 1450 doc := fixORDDocument() 1451 doc.Packages[0].LineOfBusiness = json.RawMessage(invalidLineOfBusinessNonStringElement) 1452 1453 return []*ord.Document{doc} 1454 }, 1455 }, { 1456 Name: "Invalid `lineOfBusiness` field when it is invalid JSON for Package", 1457 DocumentProvider: func() []*ord.Document { 1458 doc := fixORDDocument() 1459 doc.Packages[0].LineOfBusiness = json.RawMessage(invalidJSON) 1460 1461 return []*ord.Document{doc} 1462 }, 1463 }, { 1464 Name: "Invalid `lineOfBusiness` field when it isn't a JSON array for Package", 1465 DocumentProvider: func() []*ord.Document { 1466 doc := fixORDDocument() 1467 doc.Packages[0].LineOfBusiness = json.RawMessage("{}") 1468 1469 return []*ord.Document{doc} 1470 }, 1471 }, { 1472 Name: "Valid `lineOfBusiness` field when the JSON array is empty", 1473 DocumentProvider: func() []*ord.Document { 1474 doc := fixORDDocument() 1475 doc.Packages[0].LineOfBusiness = json.RawMessage("[]") 1476 1477 return []*ord.Document{doc} 1478 }, 1479 ExpectedToBeValid: true, 1480 }, { 1481 Name: "Invalid `lineOfBusiness` field when `policyLevel` is `sap`", 1482 DocumentProvider: func() []*ord.Document { 1483 doc := fixORDDocument() 1484 doc.Packages[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 1485 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 1486 1487 return []*ord.Document{doc} 1488 }, 1489 }, { 1490 Name: "Valid `lineOfBusiness` field when `policyLevel` is `sap partner`", 1491 ExpectedToBeValid: true, 1492 DocumentProvider: func() []*ord.Document { 1493 doc := fixORDDocument() 1494 doc.Packages[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 1495 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 1496 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 1497 1498 return []*ord.Document{doc} 1499 }, 1500 }, { 1501 Name: "Valid `lineOfBusiness` field when `policyLevel` is `custom`", 1502 ExpectedToBeValid: true, 1503 DocumentProvider: func() []*ord.Document { 1504 doc := fixORDDocument() 1505 doc.Packages[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 1506 doc.Packages[0].PolicyLevel = ord.PolicyLevelCustom 1507 1508 return []*ord.Document{doc} 1509 }, 1510 }, { 1511 Name: "Valid `lineOfBusiness` field when `policyLevel` is `none`", 1512 ExpectedToBeValid: true, 1513 DocumentProvider: func() []*ord.Document { 1514 doc := fixORDDocument() 1515 doc.Packages[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 1516 doc.Packages[0].PolicyLevel = ord.PolicyLevelNone 1517 1518 return []*ord.Document{doc} 1519 }, 1520 }, { 1521 Name: "Invalid `industry` field element for Package", 1522 DocumentProvider: func() []*ord.Document { 1523 doc := fixORDDocument() 1524 doc.Packages[0].Industry = json.RawMessage(invalidIndustryElement) 1525 1526 return []*ord.Document{doc} 1527 }, 1528 }, { 1529 Name: "Invalid `industry` field when JSON array contains non string element for Package", 1530 DocumentProvider: func() []*ord.Document { 1531 doc := fixORDDocument() 1532 doc.Packages[0].Industry = json.RawMessage(invalidIndustryNonStringElement) 1533 1534 return []*ord.Document{doc} 1535 }, 1536 }, { 1537 Name: "Invalid `industry` field when it is invalid JSON for Package", 1538 DocumentProvider: func() []*ord.Document { 1539 doc := fixORDDocument() 1540 doc.Packages[0].Industry = json.RawMessage(invalidJSON) 1541 1542 return []*ord.Document{doc} 1543 }, 1544 }, { 1545 Name: "Invalid `industry` field when it isn't a JSON array for Package", 1546 DocumentProvider: func() []*ord.Document { 1547 doc := fixORDDocument() 1548 doc.Packages[0].Industry = json.RawMessage("{}") 1549 1550 return []*ord.Document{doc} 1551 }, 1552 }, { 1553 Name: "Valid `industry` field when the JSON array is empty", 1554 DocumentProvider: func() []*ord.Document { 1555 doc := fixORDDocument() 1556 doc.Packages[0].Industry = json.RawMessage("[]") 1557 1558 return []*ord.Document{doc} 1559 }, 1560 ExpectedToBeValid: true, 1561 }, { 1562 Name: "Invalid `industry` field when `policyLevel` is `sap`", 1563 DocumentProvider: func() []*ord.Document { 1564 doc := fixORDDocument() 1565 doc.Packages[0].Industry = json.RawMessage(`["SomeIndustry"]`) 1566 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 1567 1568 return []*ord.Document{doc} 1569 }, 1570 }, { 1571 Name: "Valid `industry` field when `policyLevel` is `sap partner`", 1572 ExpectedToBeValid: true, 1573 DocumentProvider: func() []*ord.Document { 1574 doc := fixORDDocument() 1575 doc.Packages[0].Industry = json.RawMessage(`["SomeIndustry"]`) 1576 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 1577 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 1578 1579 return []*ord.Document{doc} 1580 }, 1581 }, { 1582 Name: "Valid `industry` field when `policyLevel` is `custom`", 1583 ExpectedToBeValid: true, 1584 DocumentProvider: func() []*ord.Document { 1585 doc := fixORDDocument() 1586 doc.Packages[0].Industry = json.RawMessage(`["SomeIndustry"]`) 1587 doc.Packages[0].PolicyLevel = ord.PolicyLevelCustom 1588 1589 return []*ord.Document{doc} 1590 }, 1591 }, { 1592 Name: "Valid `industry` field when `policyLevel` is `none`", 1593 ExpectedToBeValid: true, 1594 DocumentProvider: func() []*ord.Document { 1595 doc := fixORDDocument() 1596 doc.Packages[0].Industry = json.RawMessage(`["SomeIndustry"]`) 1597 doc.Packages[0].PolicyLevel = ord.PolicyLevelNone 1598 1599 return []*ord.Document{doc} 1600 }, 1601 }, 1602 { 1603 Name: "Invalid empty `supportInfo` field for Package", 1604 DocumentProvider: func() []*ord.Document { 1605 doc := fixORDDocument() 1606 emptyStr := "" 1607 doc.Packages[0].SupportInfo = &emptyStr 1608 1609 return []*ord.Document{doc} 1610 }, 1611 }, 1612 1613 // Test invalid entity relations 1614 1615 { 1616 Name: "Package has a reference to unknown Vendor", 1617 DocumentProvider: func() []*ord.Document { 1618 doc := fixORDDocument() 1619 doc.Packages[0].Vendor = str.Ptr(unknownVendorOrdID) 1620 1621 return []*ord.Document{doc} 1622 }, 1623 }, { 1624 Name: "Package has a reference to unknown Product", 1625 DocumentProvider: func() []*ord.Document { 1626 doc := fixORDDocument() 1627 doc.Packages[0].PartOfProducts = json.RawMessage(fmt.Sprintf(`["%s"]`, unknownProductOrdID)) 1628 1629 return []*ord.Document{doc} 1630 }, 1631 }, 1632 } 1633 1634 for _, test := range tests { 1635 t.Run(test.Name, func(t *testing.T) { 1636 docs := ord.Documents{test.DocumentProvider()[0]} 1637 resourcesFromDB := ord.ResourcesFromDB{ 1638 APIs: apisFromDB, 1639 Events: eventsFromDB, 1640 Packages: pkgsFromDB, 1641 Bundles: bndlsFromDB, 1642 } 1643 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 1644 1645 if test.AfterTest != nil { 1646 test.AfterTest() 1647 } 1648 1649 if test.ExpectedToBeValid { 1650 require.NoError(t, err) 1651 } else { 1652 require.Error(t, err) 1653 } 1654 }) 1655 } 1656 } 1657 1658 func TestDocuments_ValidateBundle(t *testing.T) { 1659 var tests = []struct { 1660 Name string 1661 DocumentProvider func() []*ord.Document 1662 ExpectedToBeValid bool 1663 }{ 1664 { 1665 Name: "Missing `ordID` field for Bundle", 1666 DocumentProvider: func() []*ord.Document { 1667 doc := fixORDDocument() 1668 doc.ConsumptionBundles[0].OrdID = nil 1669 1670 return []*ord.Document{doc} 1671 }, 1672 }, 1673 { 1674 Name: "Invalid `ordID` field for Bundle", 1675 DocumentProvider: func() []*ord.Document { 1676 doc := fixORDDocument() 1677 doc.ConsumptionBundles[0].OrdID = str.Ptr(invalidOrdID) 1678 1679 return []*ord.Document{doc} 1680 }, 1681 }, 1682 { 1683 Name: "Missing `title` field for Bundle", 1684 DocumentProvider: func() []*ord.Document { 1685 doc := fixORDDocument() 1686 doc.ConsumptionBundles[0].Name = "" 1687 1688 return []*ord.Document{doc} 1689 }, 1690 }, 1691 { 1692 Name: "Valid missing `localTenantID` field for Bundle", 1693 DocumentProvider: func() []*ord.Document { 1694 doc := fixORDDocument() 1695 doc.ConsumptionBundles[0].LocalTenantID = nil 1696 1697 return []*ord.Document{doc} 1698 }, 1699 ExpectedToBeValid: true, 1700 }, 1701 { 1702 Name: "Exceeded length of `localTenantID` field for Bundle", 1703 DocumentProvider: func() []*ord.Document { 1704 doc := fixORDDocument() 1705 doc.ConsumptionBundles[0].LocalTenantID = str.Ptr(strings.Repeat("a", invalidLocalTenantIDLength)) 1706 1707 return []*ord.Document{doc} 1708 }, 1709 }, 1710 { 1711 Name: "Invalid empty `localTenantID` field for Bundle", 1712 DocumentProvider: func() []*ord.Document { 1713 doc := fixORDDocument() 1714 doc.ConsumptionBundles[0].LocalTenantID = str.Ptr("") 1715 1716 return []*ord.Document{doc} 1717 }, 1718 }, { 1719 Name: "Missing `version` field for Bundle", 1720 DocumentProvider: func() []*ord.Document { 1721 doc := fixORDDocument() 1722 doc.ConsumptionBundles[0].Version = nil 1723 1724 return []*ord.Document{doc} 1725 }, 1726 }, { 1727 Name: "Invalid `version` field for Bundle", 1728 DocumentProvider: func() []*ord.Document { 1729 doc := fixORDDocument() 1730 doc.ConsumptionBundles[0].Version = str.Ptr(invalidVersion) 1731 1732 return []*ord.Document{doc} 1733 }, 1734 }, 1735 { 1736 Name: "Valid missing `shortDescription` field for Bundle", 1737 DocumentProvider: func() []*ord.Document { 1738 doc := fixORDDocument() 1739 doc.ConsumptionBundles[0].ShortDescription = nil 1740 1741 return []*ord.Document{doc} 1742 }, 1743 ExpectedToBeValid: true, 1744 }, { 1745 Name: "Exceeded length of `shortDescription` field for Bundle", 1746 DocumentProvider: func() []*ord.Document { 1747 doc := fixORDDocument() 1748 doc.ConsumptionBundles[0].ShortDescription = str.Ptr(strings.Repeat("a", invalidShortDescriptionLength)) 1749 1750 return []*ord.Document{doc} 1751 }, 1752 }, { 1753 Name: "Exceeded length of `shortDescription` field for Bundle when it has special characters", 1754 DocumentProvider: func() []*ord.Document { 1755 doc := fixORDDocument() 1756 doc.ConsumptionBundles[0].ShortDescription = str.Ptr(strings.Repeat("’", invalidShortDescriptionLength)) 1757 1758 return []*ord.Document{doc} 1759 }, 1760 }, { 1761 Name: "Not exceeded length of `shortDescription` field for Bundle when it has special characters", 1762 DocumentProvider: func() []*ord.Document { 1763 doc := fixORDDocument() 1764 doc.ConsumptionBundles[0].ShortDescription = str.Ptr(strings.Repeat("’", invalidShortDescriptionLength-1)) 1765 1766 return []*ord.Document{doc} 1767 }, 1768 ExpectedToBeValid: true, 1769 }, 1770 { 1771 Name: "Invalid empty `shortDescription` field for Bundle", 1772 DocumentProvider: func() []*ord.Document { 1773 doc := fixORDDocument() 1774 doc.ConsumptionBundles[0].ShortDescription = str.Ptr("") 1775 1776 return []*ord.Document{doc} 1777 }, 1778 }, 1779 { 1780 Name: "New lines in `shortDescription` field for Bundle", 1781 DocumentProvider: func() []*ord.Document { 1782 doc := fixORDDocument() 1783 doc.ConsumptionBundles[0].ShortDescription = str.Ptr(`newLine\n`) 1784 1785 return []*ord.Document{doc} 1786 }, 1787 }, 1788 { 1789 Name: "Valid missing `description` field for Bundle", 1790 DocumentProvider: func() []*ord.Document { 1791 doc := fixORDDocument() 1792 doc.ConsumptionBundles[0].Description = nil 1793 1794 return []*ord.Document{doc} 1795 }, 1796 ExpectedToBeValid: true, 1797 }, 1798 { 1799 Name: "Exceeded length of `description` field for Bundle", 1800 DocumentProvider: func() []*ord.Document { 1801 doc := fixORDDocument() 1802 doc.ConsumptionBundles[0].Description = str.Ptr(invalidDescriptionFieldWithExceedingMaxLength) 1803 1804 return []*ord.Document{doc} 1805 }, 1806 }, 1807 { 1808 Name: "Invalid empty `description` field for Bundle", 1809 DocumentProvider: func() []*ord.Document { 1810 doc := fixORDDocument() 1811 doc.ConsumptionBundles[0].Description = str.Ptr("") 1812 1813 return []*ord.Document{doc} 1814 }, 1815 }, 1816 { 1817 Name: "Missing `title` field in `Links` field for Bundle", 1818 DocumentProvider: func() []*ord.Document { 1819 doc := fixORDDocument() 1820 doc.ConsumptionBundles[0].Links = json.RawMessage(invalidBundleLinksDueToMissingTitle) 1821 1822 return []*ord.Document{doc} 1823 }, 1824 }, 1825 { 1826 Name: "Missing `url` field in `Links` field for Bundle", 1827 DocumentProvider: func() []*ord.Document { 1828 doc := fixORDDocument() 1829 doc.ConsumptionBundles[0].Links = json.RawMessage(invalidBundleLinksDueToMissingURL) 1830 1831 return []*ord.Document{doc} 1832 }, 1833 }, 1834 { 1835 Name: "Invalid `url` field in `Links` field for Bundle", 1836 DocumentProvider: func() []*ord.Document { 1837 doc := fixORDDocument() 1838 doc.ConsumptionBundles[0].Links = json.RawMessage(invalidBundleLinksDueToWrongURL) 1839 1840 return []*ord.Document{doc} 1841 }, 1842 }, 1843 { 1844 Name: "Invalid `description` field with exceeding length in `Links` for Bundle", 1845 DocumentProvider: func() []*ord.Document { 1846 doc := fixORDDocument() 1847 doc.ConsumptionBundles[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, invalidDescriptionFieldWithExceedingMaxLength)) 1848 1849 return []*ord.Document{doc} 1850 }, 1851 }, 1852 { 1853 Name: "Invalid empty `description` field in `Links` for Bundle", 1854 DocumentProvider: func() []*ord.Document { 1855 doc := fixORDDocument() 1856 doc.ConsumptionBundles[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, "")) 1857 1858 return []*ord.Document{doc} 1859 }, 1860 }, 1861 { 1862 Name: "Invalid `Links` field when it is invalid JSON for Bundle", 1863 DocumentProvider: func() []*ord.Document { 1864 doc := fixORDDocument() 1865 doc.ConsumptionBundles[0].Links = json.RawMessage(invalidJSON) 1866 1867 return []*ord.Document{doc} 1868 }, 1869 }, 1870 { 1871 Name: "Invalid `Links` field when it isn't a JSON array for Bundle", 1872 DocumentProvider: func() []*ord.Document { 1873 doc := fixORDDocument() 1874 doc.ConsumptionBundles[0].Links = json.RawMessage("{}") 1875 1876 return []*ord.Document{doc} 1877 }, 1878 }, 1879 { 1880 Name: "Valid `Links` field when it is an empty JSON array for Bundle", 1881 DocumentProvider: func() []*ord.Document { 1882 doc := fixORDDocument() 1883 doc.ConsumptionBundles[0].Links = json.RawMessage("[]") 1884 1885 return []*ord.Document{doc} 1886 }, 1887 ExpectedToBeValid: true, 1888 }, 1889 { 1890 Name: "Invalid JSON `Labels` field for Bundle", 1891 DocumentProvider: func() []*ord.Document { 1892 doc := fixORDDocument() 1893 doc.ConsumptionBundles[0].Labels = json.RawMessage(invalidJSON) 1894 1895 return []*ord.Document{doc} 1896 }, 1897 }, 1898 { 1899 Name: "Invalid JSON object `Labels` field for Bundle", 1900 DocumentProvider: func() []*ord.Document { 1901 doc := fixORDDocument() 1902 doc.ConsumptionBundles[0].Labels = json.RawMessage(`[]`) 1903 1904 return []*ord.Document{doc} 1905 }, 1906 }, 1907 { 1908 Name: "`Labels` values are not array for Bundle", 1909 DocumentProvider: func() []*ord.Document { 1910 doc := fixORDDocument() 1911 doc.ConsumptionBundles[0].Labels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 1912 1913 return []*ord.Document{doc} 1914 }, 1915 }, 1916 { 1917 Name: "`Labels` values are not array of strings for Bundle", 1918 DocumentProvider: func() []*ord.Document { 1919 doc := fixORDDocument() 1920 doc.ConsumptionBundles[0].Labels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 1921 1922 return []*ord.Document{doc} 1923 }, 1924 }, 1925 { 1926 Name: "Invalid key for JSON `Labels` field for Bundle", 1927 DocumentProvider: func() []*ord.Document { 1928 doc := fixORDDocument() 1929 doc.ConsumptionBundles[0].Labels = json.RawMessage(invalidLabelsWhenKeyIsWrong) 1930 1931 return []*ord.Document{doc} 1932 }, 1933 }, 1934 { 1935 Name: "Invalid JSON `DocumentationLabels` field for Bundle", 1936 DocumentProvider: func() []*ord.Document { 1937 doc := fixORDDocument() 1938 doc.ConsumptionBundles[0].DocumentationLabels = json.RawMessage(invalidJSON) 1939 1940 return []*ord.Document{doc} 1941 }, 1942 }, 1943 { 1944 Name: "Invalid JSON object `DocumentationLabels` field for Bundle", 1945 DocumentProvider: func() []*ord.Document { 1946 doc := fixORDDocument() 1947 doc.ConsumptionBundles[0].DocumentationLabels = json.RawMessage(`[]`) 1948 1949 return []*ord.Document{doc} 1950 }, 1951 }, 1952 { 1953 Name: "`DocumentationLabels` values are not array for Bundle", 1954 DocumentProvider: func() []*ord.Document { 1955 doc := fixORDDocument() 1956 doc.ConsumptionBundles[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 1957 1958 return []*ord.Document{doc} 1959 }, 1960 }, 1961 { 1962 Name: "`DocumentationLabels` values are not array of strings for Bundle", 1963 DocumentProvider: func() []*ord.Document { 1964 doc := fixORDDocument() 1965 doc.ConsumptionBundles[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 1966 1967 return []*ord.Document{doc} 1968 }, 1969 }, 1970 { 1971 Name: "Missing `type` field of `CredentialExchangeStrategies` field for Bundle", 1972 DocumentProvider: func() []*ord.Document { 1973 doc := fixORDDocument() 1974 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(invalidCredentialsExchangeStrategyDueToMissingType) 1975 1976 return []*ord.Document{doc} 1977 }, 1978 }, 1979 { 1980 Name: "Invalid `type` field of `CredentialExchangeStrategies` field for Bundle", 1981 DocumentProvider: func() []*ord.Document { 1982 doc := fixORDDocument() 1983 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(invalidCredentialsExchangeStrategyDueToWrongType) 1984 1985 return []*ord.Document{doc} 1986 }, 1987 }, 1988 { 1989 Name: "`type` field is not with value `custom` when `customType` field is provided for `CredentialExchangeStrategies` field for Bundle", 1990 DocumentProvider: func() []*ord.Document { 1991 doc := fixORDDocument() 1992 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(invalidCredentialsExchangeStrategyDueToWrongCustomType) 1993 1994 return []*ord.Document{doc} 1995 }, 1996 }, 1997 { 1998 Name: "Invalid `customType` field when `type` field is set to `custom` for `CredentialExchangeStrategies` field for Bundle", 1999 DocumentProvider: func() []*ord.Document { 2000 doc := fixORDDocument() 2001 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(fmt.Sprintf(invalidCredentialsExchangeStrategyDueToWrongTenantMappingCustomType, ord.TenantMappingCustomTypeIdentifier)) 2002 2003 return []*ord.Document{doc} 2004 }, 2005 }, 2006 { 2007 Name: "Invalid `customType` tenant mapping field when `type` field is set to `custom` for `CredentialExchangeStrategies` field for Bundle", 2008 DocumentProvider: func() []*ord.Document { 2009 doc := fixORDDocument() 2010 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(invalidCredentialsExchangeStrategyDueToWrongCustomType) 2011 2012 return []*ord.Document{doc} 2013 }, 2014 }, 2015 { 2016 Name: "`type` field is not with value `custom` when `customDescription` field is provided for `CredentialExchangeStrategies` field for Bundle", 2017 DocumentProvider: func() []*ord.Document { 2018 doc := fixORDDocument() 2019 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(invalidCredentialsExchangeStrategyDueToMissingCustomType) 2020 2021 return []*ord.Document{doc} 2022 }, 2023 }, 2024 { 2025 Name: "`type` field is with value `custom` but `customDescription` field is empty for `CredentialExchangeStrategies` field for Bundle", 2026 DocumentProvider: func() []*ord.Document { 2027 doc := fixORDDocument() 2028 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(fmt.Sprintf(invalidCredentialsExchangeStrategyDueToInvalidLenOfCustomDescription, "")) 2029 2030 return []*ord.Document{doc} 2031 }, 2032 }, 2033 { 2034 Name: "`type` field is with value `custom` but `customDescription` field is with exceeding length for `CredentialExchangeStrategies` field for Bundle", 2035 DocumentProvider: func() []*ord.Document { 2036 doc := fixORDDocument() 2037 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(fmt.Sprintf(invalidCredentialsExchangeStrategyDueToInvalidLenOfCustomDescription, invalidDescriptionFieldWithExceedingMaxLength)) 2038 2039 return []*ord.Document{doc} 2040 }, 2041 }, 2042 { 2043 Name: "Invalid `callbackURL` field of `CredentialExchangeStrategies` field for Bundle", 2044 DocumentProvider: func() []*ord.Document { 2045 doc := fixORDDocument() 2046 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(invalidCredentialsExchangeStrategyDueToWrongCallbackURL) 2047 2048 return []*ord.Document{doc} 2049 }, 2050 }, 2051 { 2052 Name: "Invalid `CredentialExchangeStrategies` field when it is invalid JSON for Bundle", 2053 DocumentProvider: func() []*ord.Document { 2054 doc := fixORDDocument() 2055 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage(invalidJSON) 2056 2057 return []*ord.Document{doc} 2058 }, 2059 }, 2060 { 2061 Name: "Invalid `CredentialExchangeStrategies` field when it isn't a JSON array for Bundle", 2062 DocumentProvider: func() []*ord.Document { 2063 doc := fixORDDocument() 2064 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage("{}") 2065 2066 return []*ord.Document{doc} 2067 }, 2068 }, 2069 { 2070 Name: "Valid `CredentialExchangeStrategies` field when it is an empty JSON array for Bundle", 2071 DocumentProvider: func() []*ord.Document { 2072 doc := fixORDDocument() 2073 doc.ConsumptionBundles[0].CredentialExchangeStrategies = json.RawMessage("[]") 2074 2075 return []*ord.Document{doc} 2076 }, 2077 ExpectedToBeValid: true, 2078 }, 2079 { 2080 Name: "Invalid `correlationIds` field when it is invalid JSON for Bundle", 2081 DocumentProvider: func() []*ord.Document { 2082 doc := fixORDDocument() 2083 doc.ConsumptionBundles[0].CorrelationIDs = json.RawMessage(invalidJSON) 2084 2085 return []*ord.Document{doc} 2086 }, 2087 }, 2088 { 2089 Name: "Invalid `correlationIds` field when it isn't a JSON array for Bundle", 2090 DocumentProvider: func() []*ord.Document { 2091 doc := fixORDDocument() 2092 doc.ConsumptionBundles[0].CorrelationIDs = json.RawMessage("{}") 2093 2094 return []*ord.Document{doc} 2095 }, 2096 }, 2097 { 2098 Name: "Valid `correlationIds` field when it is an empty JSON array for Bundle", 2099 DocumentProvider: func() []*ord.Document { 2100 doc := fixORDDocument() 2101 doc.ConsumptionBundles[0].CorrelationIDs = json.RawMessage("[]") 2102 2103 return []*ord.Document{doc} 2104 }, 2105 ExpectedToBeValid: true, 2106 }, 2107 { 2108 Name: "Invalid `correlationIds` field when it contains non string value for Bundle", 2109 DocumentProvider: func() []*ord.Document { 2110 doc := fixORDDocument() 2111 doc.ConsumptionBundles[0].CorrelationIDs = json.RawMessage(invalidCorrelationIDsNonStringElement) 2112 2113 return []*ord.Document{doc} 2114 }, 2115 }, 2116 { 2117 Name: "Invalid value for `correlationIds` field for Bundle", 2118 DocumentProvider: func() []*ord.Document { 2119 doc := fixORDDocument() 2120 doc.ConsumptionBundles[0].CorrelationIDs = json.RawMessage(invalidCorrelationIDsElement) 2121 2122 return []*ord.Document{doc} 2123 }, 2124 }, 2125 { 2126 Name: "Success when `correlationIds` are valid", 2127 DocumentProvider: func() []*ord.Document { 2128 return []*ord.Document{fixORDDocument()} 2129 }, 2130 ExpectedToBeValid: true, 2131 }, 2132 } 2133 2134 for _, test := range tests { 2135 t.Run(test.Name, func(t *testing.T) { 2136 docs := ord.Documents{test.DocumentProvider()[0]} 2137 resourcesFromDB := ord.ResourcesFromDB{ 2138 APIs: apisFromDB, 2139 Events: eventsFromDB, 2140 Packages: pkgsFromDB, 2141 Bundles: bndlsFromDB, 2142 } 2143 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 2144 if test.ExpectedToBeValid { 2145 require.NoError(t, err) 2146 } else { 2147 require.Error(t, err) 2148 } 2149 }) 2150 } 2151 } 2152 2153 func TestDocuments_ValidateAPI(t *testing.T) { 2154 var tests = []struct { 2155 Name string 2156 DocumentProvider func() []*ord.Document 2157 ExpectedToBeValid bool 2158 AfterTest func() 2159 }{ 2160 { 2161 Name: "Missing `ordID` field for API", 2162 DocumentProvider: func() []*ord.Document { 2163 doc := fixORDDocument() 2164 doc.APIResources[0].OrdID = nil 2165 2166 return []*ord.Document{doc} 2167 }, 2168 }, { 2169 Name: "Invalid `ordID` field for API", 2170 DocumentProvider: func() []*ord.Document { 2171 doc := fixORDDocument() 2172 doc.APIResources[0].OrdID = str.Ptr(invalidOrdID) 2173 2174 return []*ord.Document{doc} 2175 }, 2176 }, { 2177 Name: "Missing `title` field for API", 2178 DocumentProvider: func() []*ord.Document { 2179 doc := fixORDDocument() 2180 doc.APIResources[0].Name = "" 2181 2182 return []*ord.Document{doc} 2183 }, 2184 }, { 2185 Name: "Missing `localTenantID` field for API", 2186 DocumentProvider: func() []*ord.Document { 2187 doc := fixORDDocument() 2188 doc.APIResources[0].LocalTenantID = nil 2189 2190 return []*ord.Document{doc} 2191 }, 2192 ExpectedToBeValid: true, 2193 }, { 2194 Name: "Exceeded length of `localTenantID` field for API", 2195 DocumentProvider: func() []*ord.Document { 2196 doc := fixORDDocument() 2197 doc.APIResources[0].LocalTenantID = str.Ptr(strings.Repeat("a", invalidLocalTenantIDLength)) 2198 2199 return []*ord.Document{doc} 2200 }, 2201 }, { 2202 Name: "Invalid empty `localTenantID` field for API", 2203 DocumentProvider: func() []*ord.Document { 2204 doc := fixORDDocument() 2205 doc.APIResources[0].LocalTenantID = str.Ptr("") 2206 return []*ord.Document{doc} 2207 }, 2208 }, { 2209 Name: "Missing `shortDescription` field for API", 2210 DocumentProvider: func() []*ord.Document { 2211 doc := fixORDDocument() 2212 doc.APIResources[0].ShortDescription = nil 2213 2214 return []*ord.Document{doc} 2215 }, 2216 }, { 2217 Name: "Exceeded length of `shortDescription` field for API", 2218 DocumentProvider: func() []*ord.Document { 2219 doc := fixORDDocument() 2220 doc.APIResources[0].ShortDescription = str.Ptr(strings.Repeat("a", invalidShortDescriptionLength)) 2221 2222 return []*ord.Document{doc} 2223 }, 2224 }, { 2225 Name: "Invalid empty `shortDescription` field for API", 2226 DocumentProvider: func() []*ord.Document { 2227 doc := fixORDDocument() 2228 doc.APIResources[0].ShortDescription = str.Ptr("") 2229 return []*ord.Document{doc} 2230 }, 2231 }, { 2232 Name: "New lines in `shortDescription` field for API", 2233 DocumentProvider: func() []*ord.Document { 2234 doc := fixORDDocument() 2235 doc.APIResources[0].ShortDescription = str.Ptr(`newLine\n`) 2236 2237 return []*ord.Document{doc} 2238 }, 2239 }, { 2240 Name: "Missing `description` field for API", 2241 DocumentProvider: func() []*ord.Document { 2242 doc := fixORDDocument() 2243 doc.APIResources[0].Description = nil 2244 2245 return []*ord.Document{doc} 2246 }, 2247 }, { 2248 Name: "Invalid `description` field with exceeding max length for API", 2249 DocumentProvider: func() []*ord.Document { 2250 doc := fixORDDocument() 2251 doc.APIResources[0].Description = str.Ptr(invalidDescriptionFieldWithExceedingMaxLength) 2252 2253 return []*ord.Document{doc} 2254 }, 2255 }, { 2256 Name: "Missing `version` field for API", 2257 DocumentProvider: func() []*ord.Document { 2258 doc := fixORDDocument() 2259 doc.APIResources[0].VersionInput.Value = "" 2260 2261 return []*ord.Document{doc} 2262 }, 2263 }, { 2264 Name: "Invalid `version` field for API", 2265 DocumentProvider: func() []*ord.Document { 2266 doc := fixORDDocument() 2267 doc.APIResources[0].VersionInput.Value = invalidVersion 2268 2269 return []*ord.Document{doc} 2270 }, 2271 }, { 2272 Name: "Not incremented `version` field when resource definition's URL has changed for API", 2273 DocumentProvider: func() []*ord.Document { 2274 doc := fixORDDocument() 2275 doc.APIResources[0].ResourceDefinitions[0].URL = "http://newurl.com/odata/$metadata" 2276 2277 newHash, err := ord.HashObject(doc.APIResources[0]) 2278 require.NoError(t, err) 2279 2280 resourceHashes[api1ORDID] = newHash 2281 2282 return []*ord.Document{doc} 2283 }, 2284 AfterTest: func() { 2285 resourceHashes = fixResourceHashes() 2286 }, 2287 }, { 2288 Name: "Not incremented `version` field when resource definition's MediaType has changed for API", 2289 DocumentProvider: func() []*ord.Document { 2290 doc := fixORDDocument() 2291 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 2292 2293 newHash, err := ord.HashObject(doc.APIResources[0]) 2294 require.NoError(t, err) 2295 2296 resourceHashes[api1ORDID] = newHash 2297 2298 return []*ord.Document{doc} 2299 }, 2300 AfterTest: func() { 2301 resourceHashes = fixResourceHashes() 2302 }, 2303 }, { 2304 Name: "Not incremented `version` field when resource definition's Type has changed for API", 2305 DocumentProvider: func() []*ord.Document { 2306 doc := fixORDDocument() 2307 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 2308 2309 newHash, err := ord.HashObject(doc.APIResources[0]) 2310 require.NoError(t, err) 2311 2312 resourceHashes[api1ORDID] = newHash 2313 2314 return []*ord.Document{doc} 2315 }, 2316 AfterTest: func() { 2317 resourceHashes = fixResourceHashes() 2318 }, 2319 }, { 2320 Name: "Not incremented `version` field when resource definition's CustomType has changed for API", 2321 DocumentProvider: func() []*ord.Document { 2322 doc := fixORDDocument() 2323 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeCustom 2324 doc.APIResources[0].ResourceDefinitions[0].CustomType = "sap:custom-definition-format:v1" 2325 2326 newHash, err := ord.HashObject(doc.APIResources[0]) 2327 require.NoError(t, err) 2328 2329 resourceHashes[api1ORDID] = newHash 2330 2331 return []*ord.Document{doc} 2332 }, 2333 AfterTest: func() { 2334 resourceHashes = fixResourceHashes() 2335 }, 2336 }, { 2337 Name: "Not incremented `version` field when resource has changed for API", 2338 DocumentProvider: func() []*ord.Document { 2339 doc := fixORDDocument() 2340 doc.APIResources[0].Industry = json.RawMessage(`["Utilities"]`) 2341 2342 newHash, err := ord.HashObject(doc.APIResources[0]) 2343 require.NoError(t, err) 2344 2345 resourceHashes[api1ORDID] = newHash 2346 2347 return []*ord.Document{doc} 2348 }, 2349 AfterTest: func() { 2350 resourceHashes = fixResourceHashes() 2351 }, 2352 }, { 2353 Name: "Valid incremented `version` field when resource definition has changed for API", 2354 DocumentProvider: func() []*ord.Document { 2355 doc := fixORDDocument() 2356 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeCustom 2357 doc.APIResources[0].ResourceDefinitions[0].CustomType = "sap:custom-definition-format:v1" 2358 doc.APIResources[0].VersionInput.Value = "2.1.4" 2359 2360 newHash, err := ord.HashObject(doc.APIResources[0]) 2361 require.NoError(t, err) 2362 2363 resourceHashes[api1ORDID] = newHash 2364 2365 return []*ord.Document{doc} 2366 }, 2367 AfterTest: func() { 2368 resourceHashes = fixResourceHashes() 2369 }, 2370 ExpectedToBeValid: true, 2371 }, { 2372 Name: "Missing `partOfPackage` field for API", 2373 DocumentProvider: func() []*ord.Document { 2374 doc := fixORDDocument() 2375 doc.APIResources[0].OrdPackageID = nil 2376 2377 return []*ord.Document{doc} 2378 }, 2379 }, { 2380 Name: "Invalid `partOfPackage` field for API", 2381 DocumentProvider: func() []*ord.Document { 2382 doc := fixORDDocument() 2383 doc.APIResources[0].OrdPackageID = str.Ptr(invalidOrdID) 2384 2385 return []*ord.Document{doc} 2386 }, 2387 }, { 2388 Name: "Missing `apiProtocol` field for API", 2389 DocumentProvider: func() []*ord.Document { 2390 doc := fixORDDocument() 2391 doc.APIResources[0].APIProtocol = nil 2392 2393 return []*ord.Document{doc} 2394 }, 2395 }, { 2396 Name: "Invalid `apiProtocol` field for API", 2397 DocumentProvider: func() []*ord.Document { 2398 doc := fixORDDocument() 2399 doc.APIResources[0].APIProtocol = str.Ptr("wrongAPIProtocol") 2400 2401 return []*ord.Document{doc} 2402 }, 2403 }, { 2404 Name: "Missing `visibility` field for API", 2405 DocumentProvider: func() []*ord.Document { 2406 doc := fixORDDocument() 2407 doc.APIResources[0].Visibility = nil 2408 2409 return []*ord.Document{doc} 2410 }, 2411 }, { 2412 Name: "Invalid `visibility` field for API", 2413 DocumentProvider: func() []*ord.Document { 2414 doc := fixORDDocument() 2415 doc.APIResources[0].Visibility = str.Ptr("wrongVisibility") 2416 2417 return []*ord.Document{doc} 2418 }, 2419 }, { 2420 Name: "Invalid element of `partOfProducts` array field for API", 2421 DocumentProvider: func() []*ord.Document { 2422 doc := fixORDDocument() 2423 doc.APIResources[0].PartOfProducts = json.RawMessage(invalidPartOfProductsElement) 2424 2425 return []*ord.Document{doc} 2426 }, 2427 }, { 2428 Name: "Valid `partOfProducts` field when the JSON array is empty for API", 2429 DocumentProvider: func() []*ord.Document { 2430 doc := fixORDDocument() 2431 doc.APIResources[0].PartOfProducts = json.RawMessage("[]") 2432 2433 return []*ord.Document{doc} 2434 }, 2435 ExpectedToBeValid: true, 2436 }, { 2437 Name: "Invalid `partOfProducts` field when it is invalid JSON for API", 2438 DocumentProvider: func() []*ord.Document { 2439 doc := fixORDDocument() 2440 doc.APIResources[0].PartOfProducts = json.RawMessage(invalidJSON) 2441 2442 return []*ord.Document{doc} 2443 }, 2444 }, { 2445 Name: "Invalid `partOfProducts` field when it isn't a JSON array for API", 2446 DocumentProvider: func() []*ord.Document { 2447 doc := fixORDDocument() 2448 doc.APIResources[0].PartOfProducts = json.RawMessage("{}") 2449 2450 return []*ord.Document{doc} 2451 }, 2452 }, { 2453 Name: "Invalid `partOfProducts` field when it contains non string value for API", 2454 DocumentProvider: func() []*ord.Document { 2455 doc := fixORDDocument() 2456 doc.APIResources[0].PartOfProducts = json.RawMessage(invalidPartOfProductsIntegerElement) 2457 2458 return []*ord.Document{doc} 2459 }, 2460 }, { 2461 Name: "Invalid value for `tags` field for API", 2462 DocumentProvider: func() []*ord.Document { 2463 doc := fixORDDocument() 2464 doc.APIResources[0].Tags = json.RawMessage(invalidTagsValue) 2465 2466 return []*ord.Document{doc} 2467 }, 2468 }, { 2469 Name: "Invalid `tags` field when it is invalid JSON for API", 2470 DocumentProvider: func() []*ord.Document { 2471 doc := fixORDDocument() 2472 doc.APIResources[0].Tags = json.RawMessage(invalidJSON) 2473 2474 return []*ord.Document{doc} 2475 }, 2476 }, { 2477 Name: "Invalid `tags` field when it isn't a JSON array for API", 2478 DocumentProvider: func() []*ord.Document { 2479 doc := fixORDDocument() 2480 doc.APIResources[0].Tags = json.RawMessage("{}") 2481 2482 return []*ord.Document{doc} 2483 }, 2484 }, { 2485 Name: "Valid `tags` field when the JSON array is empty for API", 2486 DocumentProvider: func() []*ord.Document { 2487 doc := fixORDDocument() 2488 doc.APIResources[0].Tags = json.RawMessage("[]") 2489 2490 return []*ord.Document{doc} 2491 }, 2492 ExpectedToBeValid: true, 2493 }, { 2494 Name: "Invalid `tags` field when it contains non string value for API", 2495 DocumentProvider: func() []*ord.Document { 2496 doc := fixORDDocument() 2497 doc.APIResources[0].Tags = json.RawMessage(invalidTagsValueIntegerElement) 2498 2499 return []*ord.Document{doc} 2500 }, 2501 }, { 2502 Name: "Invalid value for `supportedUseCases` field for API", 2503 DocumentProvider: func() []*ord.Document { 2504 doc := fixORDDocument() 2505 doc.APIResources[0].SupportedUseCases = json.RawMessage(invalidSupportedUseCasesValue) 2506 2507 return []*ord.Document{doc} 2508 }, 2509 }, { 2510 Name: "Invalid `supportedUseCases` field when it is invalid JSON for API", 2511 DocumentProvider: func() []*ord.Document { 2512 doc := fixORDDocument() 2513 doc.APIResources[0].SupportedUseCases = json.RawMessage(invalidJSON) 2514 2515 return []*ord.Document{doc} 2516 }, 2517 }, { 2518 Name: "Invalid `supportedUseCases` field when it isn't a JSON array for API", 2519 DocumentProvider: func() []*ord.Document { 2520 doc := fixORDDocument() 2521 doc.APIResources[0].SupportedUseCases = json.RawMessage("{}") 2522 2523 return []*ord.Document{doc} 2524 }, 2525 }, { 2526 Name: "Valid `supportedUseCases` field when the JSON array is empty for API", 2527 DocumentProvider: func() []*ord.Document { 2528 doc := fixORDDocument() 2529 doc.APIResources[0].SupportedUseCases = json.RawMessage("[]") 2530 2531 return []*ord.Document{doc} 2532 }, 2533 ExpectedToBeValid: true, 2534 }, { 2535 Name: "Valid `supportedUseCases` field when the JSON array is one of enumerated values for API", 2536 DocumentProvider: func() []*ord.Document { 2537 doc := fixORDDocument() 2538 doc.APIResources[0].SupportedUseCases = json.RawMessage(validSupportedUseCasesValue) 2539 2540 return []*ord.Document{doc} 2541 }, 2542 ExpectedToBeValid: true, 2543 }, { 2544 Name: "Invalid value for `countries` field for API", 2545 DocumentProvider: func() []*ord.Document { 2546 doc := fixORDDocument() 2547 doc.APIResources[0].Countries = json.RawMessage(invalidCountriesElement) 2548 2549 return []*ord.Document{doc} 2550 }, 2551 }, { 2552 Name: "Invalid `countries` field when it is invalid JSON for API", 2553 DocumentProvider: func() []*ord.Document { 2554 doc := fixORDDocument() 2555 doc.APIResources[0].Countries = json.RawMessage(invalidJSON) 2556 2557 return []*ord.Document{doc} 2558 }, 2559 }, { 2560 Name: "Invalid `countries` field when it isn't a JSON array for API", 2561 DocumentProvider: func() []*ord.Document { 2562 doc := fixORDDocument() 2563 doc.APIResources[0].Countries = json.RawMessage("{}") 2564 2565 return []*ord.Document{doc} 2566 }, 2567 }, { 2568 Name: "Valid `countries` field when the JSON array is empty for API", 2569 DocumentProvider: func() []*ord.Document { 2570 doc := fixORDDocument() 2571 doc.APIResources[0].Countries = json.RawMessage("[]") 2572 2573 return []*ord.Document{doc} 2574 }, 2575 ExpectedToBeValid: true, 2576 }, { 2577 Name: "Invalid `countries` field when it contains non string value for API", 2578 DocumentProvider: func() []*ord.Document { 2579 doc := fixORDDocument() 2580 doc.APIResources[0].Countries = json.RawMessage(invalidCountriesNonStringElement) 2581 2582 return []*ord.Document{doc} 2583 }, 2584 }, { 2585 Name: "Invalid value for `lineOfBusiness` field for API", 2586 DocumentProvider: func() []*ord.Document { 2587 doc := fixORDDocument() 2588 doc.APIResources[0].LineOfBusiness = json.RawMessage(invalidLineOfBusinessElement) 2589 2590 return []*ord.Document{doc} 2591 }, 2592 }, { 2593 Name: "Invalid `lineOfBusiness` field when it is invalid JSON for API", 2594 DocumentProvider: func() []*ord.Document { 2595 doc := fixORDDocument() 2596 doc.APIResources[0].LineOfBusiness = json.RawMessage(invalidJSON) 2597 2598 return []*ord.Document{doc} 2599 }, 2600 }, { 2601 Name: "Invalid `lineOfBusiness` field when it isn't a JSON array for API", 2602 DocumentProvider: func() []*ord.Document { 2603 doc := fixORDDocument() 2604 doc.APIResources[0].LineOfBusiness = json.RawMessage("{}") 2605 2606 return []*ord.Document{doc} 2607 }, 2608 }, { 2609 Name: "Valid `lineOfBusiness` field when the JSON array is empty for API", 2610 DocumentProvider: func() []*ord.Document { 2611 doc := fixORDDocument() 2612 doc.APIResources[0].LineOfBusiness = json.RawMessage("[]") 2613 2614 return []*ord.Document{doc} 2615 }, 2616 ExpectedToBeValid: true, 2617 }, { 2618 Name: "Invalid `lineOfBusiness` field when it contains non string value for API", 2619 DocumentProvider: func() []*ord.Document { 2620 doc := fixORDDocument() 2621 doc.APIResources[0].LineOfBusiness = json.RawMessage(invalidCountriesNonStringElement) 2622 2623 return []*ord.Document{doc} 2624 }, 2625 }, { 2626 Name: "Invalid `lineOfBusiness` field when `policyLevel` is `sap` for API", 2627 DocumentProvider: func() []*ord.Document { 2628 doc := fixORDDocument() 2629 doc.APIResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 2630 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 2631 2632 return []*ord.Document{doc} 2633 }, 2634 }, { 2635 Name: "Valid `lineOfBusiness` field when `policyLevel` is `sap partner` for API", 2636 ExpectedToBeValid: true, 2637 DocumentProvider: func() []*ord.Document { 2638 doc := fixORDDocument() 2639 doc.APIResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 2640 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 2641 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 2642 2643 return []*ord.Document{doc} 2644 }, 2645 }, { 2646 Name: "Valid `lineOfBusiness` field when `policyLevel` is `custom` for API", 2647 ExpectedToBeValid: true, 2648 DocumentProvider: func() []*ord.Document { 2649 doc := fixORDDocument() 2650 doc.APIResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 2651 doc.Packages[0].PolicyLevel = ord.PolicyLevelCustom 2652 2653 return []*ord.Document{doc} 2654 }, 2655 }, { 2656 Name: "Valid `lineOfBusiness` field when `policyLevel` is `none` for API", 2657 ExpectedToBeValid: true, 2658 DocumentProvider: func() []*ord.Document { 2659 doc := fixORDDocument() 2660 doc.APIResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 2661 doc.Packages[0].PolicyLevel = ord.PolicyLevelNone 2662 2663 return []*ord.Document{doc} 2664 }, 2665 }, { 2666 Name: "Invalid value for `industry` field for API", 2667 DocumentProvider: func() []*ord.Document { 2668 doc := fixORDDocument() 2669 doc.APIResources[0].Industry = json.RawMessage(invalidIndustryElement) 2670 2671 return []*ord.Document{doc} 2672 }, 2673 }, { 2674 Name: "Invalid `industry` field when it is invalid JSON for API", 2675 DocumentProvider: func() []*ord.Document { 2676 doc := fixORDDocument() 2677 doc.APIResources[0].Industry = json.RawMessage(invalidJSON) 2678 2679 return []*ord.Document{doc} 2680 }, 2681 }, { 2682 Name: "Invalid `industry` field when it isn't a JSON array for API", 2683 DocumentProvider: func() []*ord.Document { 2684 doc := fixORDDocument() 2685 doc.APIResources[0].Industry = json.RawMessage("{}") 2686 2687 return []*ord.Document{doc} 2688 }, 2689 }, { 2690 Name: "Valid `industry` field when the JSON array is empty for API", 2691 DocumentProvider: func() []*ord.Document { 2692 doc := fixORDDocument() 2693 doc.APIResources[0].Industry = json.RawMessage("[]") 2694 2695 return []*ord.Document{doc} 2696 }, 2697 ExpectedToBeValid: true, 2698 }, { 2699 Name: "Invalid `industry` field when it contains non string value for API", 2700 DocumentProvider: func() []*ord.Document { 2701 doc := fixORDDocument() 2702 doc.APIResources[0].Industry = json.RawMessage(invalidIndustryNonStringElement) 2703 2704 return []*ord.Document{doc} 2705 }, 2706 }, { 2707 Name: "Invalid `industry` field when `policyLevel` is `sap` for API", 2708 DocumentProvider: func() []*ord.Document { 2709 doc := fixORDDocument() 2710 doc.APIResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 2711 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 2712 2713 return []*ord.Document{doc} 2714 }, 2715 }, { 2716 Name: "Valid `industry` field when `policyLevel` is `sap partner` for API", 2717 ExpectedToBeValid: true, 2718 DocumentProvider: func() []*ord.Document { 2719 doc := fixORDDocument() 2720 doc.APIResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 2721 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 2722 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 2723 2724 return []*ord.Document{doc} 2725 }, 2726 }, { 2727 Name: "Valid `industry` field when `policyLevel` is `custom`", 2728 ExpectedToBeValid: true, 2729 DocumentProvider: func() []*ord.Document { 2730 doc := fixORDDocument() 2731 doc.APIResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 2732 doc.Packages[0].PolicyLevel = ord.PolicyLevelCustom 2733 2734 return []*ord.Document{doc} 2735 }, 2736 }, { 2737 Name: "Valid `industry` field when `policyLevel` is `none`", 2738 ExpectedToBeValid: true, 2739 DocumentProvider: func() []*ord.Document { 2740 doc := fixORDDocument() 2741 doc.APIResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 2742 doc.Packages[0].PolicyLevel = ord.PolicyLevelNone 2743 2744 return []*ord.Document{doc} 2745 }, 2746 }, { 2747 Name: "Missing `resourceDefinitions` field for API", 2748 DocumentProvider: func() []*ord.Document { 2749 doc := fixORDDocument() 2750 doc.APIResources[0].ResourceDefinitions = nil 2751 2752 return []*ord.Document{doc} 2753 }, 2754 }, { 2755 Name: "Valid missing `resourceDefinitions` field for API when `policyLevel` is sap and `visibility` is private", 2756 DocumentProvider: func() []*ord.Document { 2757 doc := fixORDDocument() 2758 doc.APIResources[0].ResourceDefinitions = nil 2759 doc.APIResources[0].Visibility = str.Ptr(ord.APIVisibilityPrivate) 2760 doc.Packages[0].PolicyLevel = policyLevel 2761 2762 return []*ord.Document{doc} 2763 }, 2764 ExpectedToBeValid: true, 2765 }, { 2766 Name: "Missing field `type` of `resourceDefinitions` field for API", 2767 DocumentProvider: func() []*ord.Document { 2768 doc := fixORDDocument() 2769 doc.APIResources[0].ResourceDefinitions[0].Type = "" 2770 2771 return []*ord.Document{doc} 2772 }, 2773 }, { 2774 Name: "Invalid field `type` of `resourceDefinitions` field for API", 2775 DocumentProvider: func() []*ord.Document { 2776 doc := fixORDDocument() 2777 doc.APIResources[0].ResourceDefinitions[0].Type = invalidType 2778 2779 return []*ord.Document{doc} 2780 }, 2781 }, { 2782 Name: "Field `type` value is not `custom` when field `customType` is provided for `resourceDefinitions` field for API", 2783 DocumentProvider: func() []*ord.Document { 2784 doc := fixORDDocument() 2785 doc.APIResources[0].ResourceDefinitions[0].CustomType = "test:test:v1" 2786 2787 return []*ord.Document{doc} 2788 }, 2789 }, { 2790 Name: "Invalid `customType` value when field `type` has value `custom`for `resourceDefinitions` field for API", 2791 DocumentProvider: func() []*ord.Document { 2792 doc := fixORDDocument() 2793 doc.APIResources[0].ResourceDefinitions[0].Type = "custom" 2794 doc.APIResources[0].ResourceDefinitions[0].CustomType = invalidCustomType 2795 2796 return []*ord.Document{doc} 2797 }, 2798 }, { 2799 Name: "Missing field `mediaType` of `resourceDefinitions` field for API", 2800 DocumentProvider: func() []*ord.Document { 2801 doc := fixORDDocument() 2802 doc.APIResources[0].ResourceDefinitions[0].MediaType = "" 2803 2804 return []*ord.Document{doc} 2805 }, 2806 }, { 2807 Name: "Invalid field `mediaType` of `resourceDefinitions` field for API", 2808 DocumentProvider: func() []*ord.Document { 2809 doc := fixORDDocument() 2810 doc.APIResources[0].ResourceDefinitions[0].MediaType = invalidMediaType 2811 2812 return []*ord.Document{doc} 2813 }, 2814 }, { 2815 Name: "Invalid field `mediaType` when field `type` has value `openapi-v2` for API", 2816 DocumentProvider: func() []*ord.Document { 2817 doc := fixORDDocument() 2818 doc.APIResources[0].ResourceDefinitions[0].Type = "openapi-v2" 2819 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/xml" 2820 2821 return []*ord.Document{doc} 2822 }, 2823 }, { 2824 Name: "Invalid field `mediaType` when field `type` has value `openapi-v3` for API", 2825 DocumentProvider: func() []*ord.Document { 2826 doc := fixORDDocument() 2827 doc.APIResources[0].ResourceDefinitions[0].Type = "openapi-v3" 2828 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/xml" 2829 2830 return []*ord.Document{doc} 2831 }, 2832 }, { 2833 Name: "Invalid field `mediaType` when field `type` has value `raml-v1` for API", 2834 DocumentProvider: func() []*ord.Document { 2835 doc := fixORDDocument() 2836 doc.APIResources[0].ResourceDefinitions[0].Type = "raml-v1" 2837 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/xml" 2838 2839 return []*ord.Document{doc} 2840 }, 2841 }, { 2842 Name: "Invalid field `mediaType` when field `type` has value `edmx` for API", 2843 DocumentProvider: func() []*ord.Document { 2844 doc := fixORDDocument() 2845 doc.APIResources[0].ResourceDefinitions[0].Type = "edmx" 2846 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/json" 2847 2848 return []*ord.Document{doc} 2849 }, 2850 }, { 2851 Name: "Invalid field `mediaType` when field `type` has value `csdl-json` for API", 2852 DocumentProvider: func() []*ord.Document { 2853 doc := fixORDDocument() 2854 doc.APIResources[0].ResourceDefinitions[0].Type = "csdl-json" 2855 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/xml" 2856 2857 return []*ord.Document{doc} 2858 }, 2859 }, { 2860 Name: "Invalid field `mediaType` when field `type` has value `wsdl-v1` for API", 2861 DocumentProvider: func() []*ord.Document { 2862 doc := fixORDDocument() 2863 doc.APIResources[0].ResourceDefinitions[0].Type = "wsdl-v1" 2864 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/json" 2865 2866 return []*ord.Document{doc} 2867 }, 2868 }, { 2869 Name: "Invalid field `mediaType` when field `type` has value `wsdl-v2` for API", 2870 DocumentProvider: func() []*ord.Document { 2871 doc := fixORDDocument() 2872 doc.APIResources[0].ResourceDefinitions[0].Type = "wsdl-v2" 2873 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/json" 2874 2875 return []*ord.Document{doc} 2876 }, 2877 }, { 2878 Name: "Invalid field `mediaType` when field `type` has value `sap-rfc-metadata-v1` for API", 2879 DocumentProvider: func() []*ord.Document { 2880 doc := fixORDDocument() 2881 doc.APIResources[0].ResourceDefinitions[0].Type = "sap-rfc-metadata-v1" 2882 doc.APIResources[0].ResourceDefinitions[0].MediaType = "application/json" 2883 2884 return []*ord.Document{doc} 2885 }, 2886 }, { 2887 Name: "Missing field `url` of `resourceDefinitions` field for API", 2888 DocumentProvider: func() []*ord.Document { 2889 doc := fixORDDocument() 2890 doc.APIResources[0].ResourceDefinitions[0].URL = "" 2891 2892 return []*ord.Document{doc} 2893 }, 2894 }, { 2895 Name: "Invalid field `url` of `resourceDefinitions` field for API", 2896 DocumentProvider: func() []*ord.Document { 2897 doc := fixORDDocument() 2898 doc.APIResources[0].ResourceDefinitions[0].URL = invalidURL 2899 2900 return []*ord.Document{doc} 2901 }, 2902 }, { 2903 Name: "Missing field `accessStrategies` of `resourceDefinitions` field for API", 2904 DocumentProvider: func() []*ord.Document { 2905 doc := fixORDDocument() 2906 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy = nil 2907 2908 return []*ord.Document{doc} 2909 }, 2910 }, { 2911 Name: "Missing field `type` for `accessStrategies` of `resourceDefinitions` field for API", 2912 DocumentProvider: func() []*ord.Document { 2913 doc := fixORDDocument() 2914 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "" 2915 2916 return []*ord.Document{doc} 2917 }, 2918 }, { 2919 Name: "Invalid field `type` for `accessStrategies` of `resourceDefinitions` field for API", 2920 DocumentProvider: func() []*ord.Document { 2921 doc := fixORDDocument() 2922 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = invalidType 2923 2924 return []*ord.Document{doc} 2925 }, 2926 }, { 2927 Name: "Invalid field `customType` when field `type` is not `custom` for `accessStrategies` of `resourceDefinitions` field for API", 2928 DocumentProvider: func() []*ord.Document { 2929 doc := fixORDDocument() 2930 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "open" 2931 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomType = "foo" 2932 2933 return []*ord.Document{doc} 2934 }, 2935 }, { 2936 Name: "Invalid field `customType` when field `type` is `custom` for `accessStrategies` of `resourceDefinitions` field for API", 2937 DocumentProvider: func() []*ord.Document { 2938 doc := fixORDDocument() 2939 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "custom" 2940 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomType = invalidCustomType 2941 2942 return []*ord.Document{doc} 2943 }, 2944 }, { 2945 Name: "Field `type` is not `custom` when `customType` is valid for `accessStrategies` of `resourceDefinitions` field for API", 2946 DocumentProvider: func() []*ord.Document { 2947 doc := fixORDDocument() 2948 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "open" 2949 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomType = "sap:custom-definition-format:v1" 2950 2951 return []*ord.Document{doc} 2952 }, 2953 }, { 2954 Name: "Invalid `customType` value when field `type` has value `custom` for `accessStrategies` field for API", 2955 DocumentProvider: func() []*ord.Document { 2956 doc := fixORDDocument() 2957 doc.APIResources[0].ResourceDefinitions[0].Type = "custom" 2958 doc.APIResources[0].ResourceDefinitions[0].CustomType = invalidCustomType 2959 2960 return []*ord.Document{doc} 2961 }, 2962 }, { 2963 Name: "Invalid field `customDescription` when field `type` is not `custom` for `accessStrategies` of `resourceDefinitions` field for API", 2964 DocumentProvider: func() []*ord.Document { 2965 doc := fixORDDocument() 2966 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "open" 2967 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomDescription = "foo" 2968 2969 return []*ord.Document{doc} 2970 }, 2971 }, { 2972 Name: "Invalid field `customDescription` with exceeding length when field `type` is `custom` for `accessStrategies` of `resourceDefinitions` field for API", 2973 DocumentProvider: func() []*ord.Document { 2974 doc := fixORDDocument() 2975 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "custom" 2976 doc.APIResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomDescription = invalidDescriptionFieldWithExceedingMaxLength 2977 2978 return []*ord.Document{doc} 2979 }, 2980 }, { 2981 Name: "Missing `type` field for `apiResourceLink` field for API", 2982 DocumentProvider: func() []*ord.Document { 2983 doc := fixORDDocument() 2984 doc.APIResources[0].APIResourceLinks = json.RawMessage(invalidAPIResourceLinksDueToMissingType) 2985 2986 return []*ord.Document{doc} 2987 }, 2988 }, { 2989 Name: "Invalid `type` field for `apiResourceLink` field for API", 2990 DocumentProvider: func() []*ord.Document { 2991 doc := fixORDDocument() 2992 doc.APIResources[0].APIResourceLinks = json.RawMessage(invalidAPIResourceLinksDueToWrongType) 2993 2994 return []*ord.Document{doc} 2995 }, 2996 }, { 2997 Name: "Invalid field `customType` when field `type` is not `custom` for `apiResourceLink` field for API", 2998 DocumentProvider: func() []*ord.Document { 2999 doc := fixORDDocument() 3000 doc.APIResources[0].APIResourceLinks = json.RawMessage(invalidAPIResourceLinksDueToMissingCustomValueOfType) 3001 3002 return []*ord.Document{doc} 3003 }, 3004 }, { 3005 Name: "Invalid field `customType` with format is wrong for API", 3006 DocumentProvider: func() []*ord.Document { 3007 doc := fixORDDocument() 3008 doc.APIResources[0].APIResourceLinks = json.RawMessage(invalidAPIResourceLinksCustomFieldDueWrongFormat) 3009 3010 return []*ord.Document{doc} 3011 }, 3012 }, { 3013 Name: "Valid field `customType` for API", 3014 DocumentProvider: func() []*ord.Document { 3015 doc := fixORDDocument() 3016 doc.APIResources[0].APIResourceLinks = json.RawMessage(validAPIResourceLinksCustomField) 3017 3018 return []*ord.Document{doc} 3019 }, 3020 ExpectedToBeValid: true, 3021 }, { 3022 Name: "Missing `url` field for `apiResourceLink` field for API", 3023 DocumentProvider: func() []*ord.Document { 3024 doc := fixORDDocument() 3025 doc.APIResources[0].APIResourceLinks = json.RawMessage(invalidAPIResourceLinksDueToMissingURL) 3026 3027 return []*ord.Document{doc} 3028 }, 3029 }, { 3030 Name: "Invalid `url` field for `apiResourceLink` field for API", 3031 DocumentProvider: func() []*ord.Document { 3032 doc := fixORDDocument() 3033 doc.APIResources[0].APIResourceLinks = json.RawMessage(invalidAPIResourceLinksDueToWrongURL) 3034 3035 return []*ord.Document{doc} 3036 }, 3037 }, { 3038 Name: "Invalid `apiResourceLink` field when it is invalid JSON for API", 3039 DocumentProvider: func() []*ord.Document { 3040 doc := fixORDDocument() 3041 doc.APIResources[0].APIResourceLinks = json.RawMessage(invalidJSON) 3042 3043 return []*ord.Document{doc} 3044 }, 3045 }, { 3046 Name: "Invalid `apiResourceLink` field when it isn't a JSON array for API", 3047 DocumentProvider: func() []*ord.Document { 3048 doc := fixORDDocument() 3049 doc.APIResources[0].APIResourceLinks = json.RawMessage("{}") 3050 3051 return []*ord.Document{doc} 3052 }, 3053 }, { 3054 Name: "Valid `apiResourceLink` field when it is an empty JSON array for API", 3055 DocumentProvider: func() []*ord.Document { 3056 doc := fixORDDocument() 3057 doc.APIResources[0].APIResourceLinks = json.RawMessage("[]") 3058 3059 return []*ord.Document{doc} 3060 }, 3061 ExpectedToBeValid: true, 3062 }, { 3063 Name: "Missing `title` field in `Links` for API", 3064 DocumentProvider: func() []*ord.Document { 3065 doc := fixORDDocument() 3066 doc.APIResources[0].Links = json.RawMessage(invalidLinkDueToMissingTitle) 3067 3068 return []*ord.Document{doc} 3069 }, 3070 }, { 3071 Name: "Missing `url` field in `Links` for API", 3072 DocumentProvider: func() []*ord.Document { 3073 doc := fixORDDocument() 3074 doc.APIResources[0].Links = json.RawMessage(invalidLinkDueToMissingURL) 3075 3076 return []*ord.Document{doc} 3077 }, 3078 }, { 3079 Name: "Invalid `url` field in `Links` for API", 3080 DocumentProvider: func() []*ord.Document { 3081 doc := fixORDDocument() 3082 doc.APIResources[0].Links = json.RawMessage(invalidLinkDueToWrongURL) 3083 3084 return []*ord.Document{doc} 3085 }, 3086 }, { 3087 Name: "Invalid `description` field with exceeding length in `Links` for API", 3088 DocumentProvider: func() []*ord.Document { 3089 doc := fixORDDocument() 3090 doc.APIResources[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, invalidDescriptionFieldWithExceedingMaxLength)) 3091 3092 return []*ord.Document{doc} 3093 }, 3094 }, { 3095 Name: "Invalid empty `description` field in `Links` for API", 3096 DocumentProvider: func() []*ord.Document { 3097 doc := fixORDDocument() 3098 doc.APIResources[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, "")) 3099 3100 return []*ord.Document{doc} 3101 }, 3102 }, { 3103 Name: "Invalid `links` field when it is invalid JSON for API", 3104 DocumentProvider: func() []*ord.Document { 3105 doc := fixORDDocument() 3106 doc.APIResources[0].Links = json.RawMessage(invalidJSON) 3107 3108 return []*ord.Document{doc} 3109 }, 3110 }, { 3111 Name: "Invalid `links` field when it isn't a JSON array for API", 3112 DocumentProvider: func() []*ord.Document { 3113 doc := fixORDDocument() 3114 doc.APIResources[0].Links = json.RawMessage("{}") 3115 3116 return []*ord.Document{doc} 3117 }, 3118 }, { 3119 Name: "Valid `links` field when it is an empty JSON array for API", 3120 DocumentProvider: func() []*ord.Document { 3121 doc := fixORDDocument() 3122 doc.APIResources[0].Links = json.RawMessage("[]") 3123 3124 return []*ord.Document{doc} 3125 }, 3126 ExpectedToBeValid: true, 3127 }, { 3128 Name: "Missing `releaseStatus` field for API", 3129 DocumentProvider: func() []*ord.Document { 3130 doc := fixORDDocument() 3131 doc.APIResources[0].ReleaseStatus = str.Ptr("") 3132 3133 return []*ord.Document{doc} 3134 }, 3135 }, { 3136 Name: "Invalid `releaseStatus` field for API", 3137 DocumentProvider: func() []*ord.Document { 3138 doc := fixORDDocument() 3139 doc.APIResources[0].ReleaseStatus = str.Ptr("wrongValue") 3140 3141 return []*ord.Document{doc} 3142 }, 3143 }, { 3144 Name: "Missing `sunsetDate` field when `releaseStatus` field has value `deprecated` for API", 3145 DocumentProvider: func() []*ord.Document { 3146 doc := fixORDDocument() 3147 doc.APIResources[0].ReleaseStatus = str.Ptr("deprecated") 3148 3149 return []*ord.Document{doc} 3150 }, 3151 }, { 3152 Name: "Invalid `sunsetDate` field for API", 3153 DocumentProvider: func() []*ord.Document { 3154 doc := fixORDDocument() 3155 doc.APIResources[0].ReleaseStatus = str.Ptr("deprecated") 3156 doc.APIResources[0].SunsetDate = str.Ptr("0000-00-00T09:35:30+0000") 3157 doc.APIResources[0].Successors = json.RawMessage(fmt.Sprintf(`["%s"]`, api2ORDID)) 3158 3159 return []*ord.Document{doc} 3160 }, 3161 }, { 3162 Name: "Missing field `version` of field `changeLogEntries` for API", 3163 DocumentProvider: func() []*ord.Document { 3164 doc := fixORDDocument() 3165 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToMissingVersion) 3166 3167 return []*ord.Document{doc} 3168 }, 3169 }, { 3170 Name: "Invalid field `version` of field `changeLogEntries` for API", 3171 DocumentProvider: func() []*ord.Document { 3172 doc := fixORDDocument() 3173 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongVersion) 3174 3175 return []*ord.Document{doc} 3176 }, 3177 }, { 3178 Name: "Missing field `releaseStatus` of field `changeLogEntries` for API", 3179 DocumentProvider: func() []*ord.Document { 3180 doc := fixORDDocument() 3181 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToMissingReleaseStatus) 3182 3183 return []*ord.Document{doc} 3184 }, 3185 }, { 3186 Name: "Invalid field `releaseStatus` of field `changeLogEntries` for API", 3187 DocumentProvider: func() []*ord.Document { 3188 doc := fixORDDocument() 3189 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongReleaseStatus) 3190 3191 return []*ord.Document{doc} 3192 }, 3193 }, { 3194 Name: "Missing field `date` of field `changeLogEntries` for API", 3195 DocumentProvider: func() []*ord.Document { 3196 doc := fixORDDocument() 3197 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToMissingDate) 3198 3199 return []*ord.Document{doc} 3200 }, 3201 }, { 3202 Name: "Invalid field `date` of field `changeLogEntries` for API", 3203 DocumentProvider: func() []*ord.Document { 3204 doc := fixORDDocument() 3205 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongDate) 3206 3207 return []*ord.Document{doc} 3208 }, 3209 }, { 3210 Name: "Invalid field `url` of field `changeLogEntries` for API", 3211 DocumentProvider: func() []*ord.Document { 3212 doc := fixORDDocument() 3213 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongURL) 3214 3215 return []*ord.Document{doc} 3216 }, 3217 }, { 3218 Name: "Invalid empty field `description` of field `changeLogEntries` for API", 3219 DocumentProvider: func() []*ord.Document { 3220 doc := fixORDDocument() 3221 doc.APIResources[0].ChangeLogEntries = json.RawMessage(fmt.Sprintf(invalidChangeLogEntriesDueToInvalidLengthOfDescription, "")) 3222 3223 return []*ord.Document{doc} 3224 }, 3225 }, { 3226 Name: "Invalid field `description` with exceeding length of field `changeLogEntries` for API", 3227 DocumentProvider: func() []*ord.Document { 3228 doc := fixORDDocument() 3229 doc.APIResources[0].ChangeLogEntries = json.RawMessage(fmt.Sprintf(invalidChangeLogEntriesDueToInvalidLengthOfDescription, invalidDescriptionFieldWithExceedingMaxLength)) 3230 3231 return []*ord.Document{doc} 3232 }, 3233 }, { 3234 Name: "Invalid `changeLogEntries` field when it is invalid JSON for API", 3235 DocumentProvider: func() []*ord.Document { 3236 doc := fixORDDocument() 3237 doc.APIResources[0].ChangeLogEntries = json.RawMessage(invalidJSON) 3238 3239 return []*ord.Document{doc} 3240 }, 3241 }, { 3242 Name: "Invalid `changeLogEntries` field when it isn't a JSON array for API", 3243 DocumentProvider: func() []*ord.Document { 3244 doc := fixORDDocument() 3245 doc.APIResources[0].ChangeLogEntries = json.RawMessage("{}") 3246 3247 return []*ord.Document{doc} 3248 }, 3249 }, { 3250 Name: "Valid `changeLogEntries` field when it is an empty JSON array for API", 3251 DocumentProvider: func() []*ord.Document { 3252 doc := fixORDDocument() 3253 doc.APIResources[0].ChangeLogEntries = json.RawMessage("[]") 3254 3255 return []*ord.Document{doc} 3256 }, 3257 ExpectedToBeValid: true, 3258 }, { 3259 Name: "Invalid when `entryPoints` field is empty but `PartOfConsumptionBundles` field is not for API", 3260 DocumentProvider: func() []*ord.Document { 3261 doc := fixORDDocument() 3262 doc.APIResources[0].TargetURLs = nil 3263 3264 return []*ord.Document{doc} 3265 }, 3266 }, { 3267 Name: "Valid when `entryPoints` field is empty and `PartOfConsumptionBundles` field is empty for API", 3268 DocumentProvider: func() []*ord.Document { 3269 doc := fixORDDocument() 3270 doc.APIResources[0].TargetURLs = nil 3271 doc.APIResources[0].PartOfConsumptionBundles = nil 3272 3273 return []*ord.Document{doc} 3274 }, 3275 ExpectedToBeValid: true, 3276 }, { 3277 Name: "Invalid when `defaultConsumptionBundle` field doesn't match the required regex for API", 3278 DocumentProvider: func() []*ord.Document { 3279 doc := fixORDDocument() 3280 doc.APIResources[0].DefaultConsumptionBundle = str.Ptr(invalidBundleOrdID) 3281 return []*ord.Document{doc} 3282 }, 3283 }, { 3284 Name: "Invalid when `defaultConsumptionBundle` field is not part of any bundles in the `partOfConsumptionBundles` field for API", 3285 DocumentProvider: func() []*ord.Document { 3286 doc := fixORDDocument() 3287 doc.APIResources[0].DefaultConsumptionBundle = str.Ptr(secondBundleORDID) 3288 return []*ord.Document{doc} 3289 }, 3290 }, { 3291 Name: "Invalid field `entryPoints` when containing invalid URI for API", 3292 DocumentProvider: func() []*ord.Document { 3293 doc := fixORDDocument() 3294 doc.APIResources[0].TargetURLs = json.RawMessage(invalidEntryPointURI) 3295 3296 return []*ord.Document{doc} 3297 }, 3298 }, { 3299 Name: "Invalid field `entryPoints` when containing duplicate URIs for API", 3300 DocumentProvider: func() []*ord.Document { 3301 doc := fixORDDocument() 3302 doc.APIResources[0].TargetURLs = json.RawMessage(invalidEntryPointsDueToDuplicates) 3303 3304 return []*ord.Document{doc} 3305 }, 3306 }, { 3307 Name: "Invalid `entryPoints` field when it is invalid JSON for API", 3308 DocumentProvider: func() []*ord.Document { 3309 doc := fixORDDocument() 3310 doc.APIResources[0].TargetURLs = json.RawMessage(invalidJSON) 3311 3312 return []*ord.Document{doc} 3313 }, 3314 }, { 3315 Name: "Invalid `entryPoints` field when it isn't a JSON array for API", 3316 DocumentProvider: func() []*ord.Document { 3317 doc := fixORDDocument() 3318 doc.APIResources[0].TargetURLs = json.RawMessage("{}") 3319 3320 return []*ord.Document{doc} 3321 }, 3322 }, { 3323 Name: "Invalid `entryPoints` field when the JSON array is empty for API", 3324 DocumentProvider: func() []*ord.Document { 3325 doc := fixORDDocument() 3326 doc.APIResources[0].TargetURLs = json.RawMessage("[]") 3327 3328 return []*ord.Document{doc} 3329 }, 3330 }, { 3331 Name: "Invalid `entryPoints` field when it contains non string value for API", 3332 DocumentProvider: func() []*ord.Document { 3333 doc := fixORDDocument() 3334 doc.APIResources[0].TargetURLs = json.RawMessage(invalidEntryPointsNonStringElement) 3335 3336 return []*ord.Document{doc} 3337 }, 3338 }, { 3339 Name: "Invalid JSON `Labels` field for API", 3340 DocumentProvider: func() []*ord.Document { 3341 doc := fixORDDocument() 3342 doc.APIResources[0].Labels = json.RawMessage(invalidJSON) 3343 3344 return []*ord.Document{doc} 3345 }, 3346 }, { 3347 Name: "Invalid JSON object `Labels` field for API", 3348 DocumentProvider: func() []*ord.Document { 3349 doc := fixORDDocument() 3350 doc.APIResources[0].Labels = json.RawMessage(`[]`) 3351 3352 return []*ord.Document{doc} 3353 }, 3354 }, { 3355 Name: "`Labels` values are not array for API", 3356 DocumentProvider: func() []*ord.Document { 3357 doc := fixORDDocument() 3358 doc.APIResources[0].Labels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 3359 3360 return []*ord.Document{doc} 3361 }, 3362 }, { 3363 Name: "`Labels` values are not array of strings for API", 3364 DocumentProvider: func() []*ord.Document { 3365 doc := fixORDDocument() 3366 doc.APIResources[0].Labels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 3367 3368 return []*ord.Document{doc} 3369 }, 3370 }, { 3371 Name: "Invalid key for JSON `Labels` field for API", 3372 DocumentProvider: func() []*ord.Document { 3373 doc := fixORDDocument() 3374 doc.APIResources[0].Labels = json.RawMessage(invalidLabelsWhenKeyIsWrong) 3375 3376 return []*ord.Document{doc} 3377 }, 3378 }, { 3379 Name: "Invalid JSON `DocumentationLabels` field for API", 3380 DocumentProvider: func() []*ord.Document { 3381 doc := fixORDDocument() 3382 doc.APIResources[0].DocumentationLabels = json.RawMessage(invalidJSON) 3383 3384 return []*ord.Document{doc} 3385 }, 3386 }, { 3387 Name: "Invalid JSON object `DocumentationLabels` field for API", 3388 DocumentProvider: func() []*ord.Document { 3389 doc := fixORDDocument() 3390 doc.APIResources[0].DocumentationLabels = json.RawMessage(`[]`) 3391 3392 return []*ord.Document{doc} 3393 }, 3394 }, { 3395 Name: "`DocumentationLabels` values are not array for API", 3396 DocumentProvider: func() []*ord.Document { 3397 doc := fixORDDocument() 3398 doc.APIResources[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 3399 3400 return []*ord.Document{doc} 3401 }, 3402 }, { 3403 Name: "`DocumentationLabels` values are not array of strings for API", 3404 DocumentProvider: func() []*ord.Document { 3405 doc := fixORDDocument() 3406 doc.APIResources[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 3407 3408 return []*ord.Document{doc} 3409 }, 3410 }, { 3411 Name: "Invalid `implementationStandard` field for API", 3412 DocumentProvider: func() []*ord.Document { 3413 doc := fixORDDocument() 3414 doc.APIResources[0].ImplementationStandard = str.Ptr(invalidType) 3415 3416 return []*ord.Document{doc} 3417 }, 3418 }, { 3419 Name: "Invalid when `customImplementationStandard` field is valid but `implementationStandard` field is missing for API", 3420 DocumentProvider: func() []*ord.Document { 3421 doc := fixORDDocument() 3422 doc.APIResources[0].ImplementationStandard = nil 3423 doc.APIResources[0].CustomImplementationStandard = str.Ptr("sap.s4:ATTACHMENT_SRV:v1") 3424 3425 return []*ord.Document{doc} 3426 }, 3427 }, { 3428 Name: "Invalid when `customImplementationStandard` field is valid but `implementationStandard` field is not set to `custom` for API", 3429 DocumentProvider: func() []*ord.Document { 3430 doc := fixORDDocument() 3431 doc.APIResources[0].CustomImplementationStandard = str.Ptr("sap.s4:ATTACHMENT_SRV:v1") 3432 3433 return []*ord.Document{doc} 3434 }, 3435 }, { 3436 Name: "Invalid `customImplementationStandard` field when `implementationStandard` field is set to `custom` for API", 3437 DocumentProvider: func() []*ord.Document { 3438 doc := fixORDDocument() 3439 doc.APIResources[0].ImplementationStandard = str.Ptr("custom") 3440 doc.APIResources[0].CustomImplementationStandard = str.Ptr(invalidType) 3441 3442 return []*ord.Document{doc} 3443 }, 3444 }, { 3445 Name: "Missing `customImplementationStandard` field when `implementationStandard` field is set to `custom` for API", 3446 DocumentProvider: func() []*ord.Document { 3447 doc := fixORDDocument() 3448 doc.APIResources[0].ImplementationStandard = str.Ptr("custom") 3449 doc.APIResources[0].CustomImplementationStandardDescription = str.Ptr("description") 3450 3451 return []*ord.Document{doc} 3452 }, 3453 }, { 3454 Name: "Invalid when `customImplementationStandardDescription` is set but `implementationStandard` field is missing for API", 3455 DocumentProvider: func() []*ord.Document { 3456 doc := fixORDDocument() 3457 doc.APIResources[0].ImplementationStandard = nil 3458 doc.APIResources[0].CustomImplementationStandardDescription = str.Ptr("description") 3459 3460 return []*ord.Document{doc} 3461 }, 3462 }, { 3463 Name: "Invalid when `customImplementationStandardDescription` is set but `implementationStandard` field is not `custom` for API", 3464 DocumentProvider: func() []*ord.Document { 3465 doc := fixORDDocument() 3466 doc.APIResources[0].CustomImplementationStandardDescription = str.Ptr("description") 3467 3468 return []*ord.Document{doc} 3469 }, 3470 }, { 3471 Name: "Invalid when `customImplementationStandardDescription` is set but `implementationStandard` field is not `custom` for API", 3472 DocumentProvider: func() []*ord.Document { 3473 doc := fixORDDocument() 3474 doc.APIResources[0].CustomImplementationStandardDescription = str.Ptr("description") 3475 3476 return []*ord.Document{doc} 3477 }, 3478 }, { 3479 Name: "Missing `customImplementationStandardDescription` field when `implementationStandard` field is set to `custom` for API", 3480 DocumentProvider: func() []*ord.Document { 3481 doc := fixORDDocument() 3482 doc.APIResources[0].ImplementationStandard = str.Ptr("custom") 3483 doc.APIResources[0].CustomImplementationStandard = str.Ptr("sap.s4:ATTACHMENT_SRV:v1") 3484 3485 return []*ord.Document{doc} 3486 }, 3487 }, { 3488 Name: "Missing `ordId` field in `PartOfConsumptionBundles` field for API", 3489 DocumentProvider: func() []*ord.Document { 3490 doc := fixORDDocument() 3491 doc.APIResources[0].PartOfConsumptionBundles[0].BundleOrdID = "" 3492 3493 return []*ord.Document{doc} 3494 }, 3495 }, { 3496 Name: "Invalid `ordId` field in `PartOfConsumptionBundles` field for API", 3497 DocumentProvider: func() []*ord.Document { 3498 doc := fixORDDocument() 3499 doc.APIResources[0].PartOfConsumptionBundles[0].BundleOrdID = invalidBundleOrdID 3500 3501 return []*ord.Document{doc} 3502 }, 3503 }, { 3504 Name: "Duplicate `ordId` field in `PartOfConsumptionBundles` field for API", 3505 DocumentProvider: func() []*ord.Document { 3506 doc := fixORDDocument() 3507 doc.APIResources[0].PartOfConsumptionBundles = append(doc.APIResources[0].PartOfConsumptionBundles, &model.ConsumptionBundleReference{BundleOrdID: bundleORDID}) 3508 3509 return []*ord.Document{doc} 3510 }, 3511 }, { 3512 Name: "Invalid `defaultEntryPoint` field in `PartOfConsumptionBundles` field for API", 3513 DocumentProvider: func() []*ord.Document { 3514 doc := fixORDDocument() 3515 doc.APIResources[0].PartOfConsumptionBundles[0].DefaultTargetURL = invalidURL 3516 3517 return []*ord.Document{doc} 3518 }, 3519 }, { 3520 Name: "Missing `defaultEntryPoint` field from `entryPoints` field for API", 3521 DocumentProvider: func() []*ord.Document { 3522 doc := fixORDDocument() 3523 doc.APIResources[0].PartOfConsumptionBundles[0].DefaultTargetURL = "https://exmaple.com/test/v3" 3524 3525 return []*ord.Document{doc} 3526 }, 3527 }, { 3528 Name: "Present `defaultEntryPoint` field even though there is a single element in `entryPoints` field for API", 3529 DocumentProvider: func() []*ord.Document { 3530 doc := fixORDDocument() 3531 doc.APIResources[1].PartOfConsumptionBundles[0].DefaultTargetURL = "https://exmaple.com/test/v3" 3532 3533 return []*ord.Document{doc} 3534 }, 3535 }, { 3536 Name: "Empty `PartOfConsumptionBundles` field for API", 3537 DocumentProvider: func() []*ord.Document { 3538 doc := fixORDDocument() 3539 doc.APIResources[0].PartOfConsumptionBundles = []*model.ConsumptionBundleReference{} 3540 3541 return []*ord.Document{doc} 3542 }, 3543 }, 3544 { 3545 Name: "Missing `Extensible` field when `policyLevel` is sap for API", 3546 DocumentProvider: func() []*ord.Document { 3547 doc := fixORDDocument() 3548 doc.APIResources[0].Extensible = nil 3549 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3550 3551 return []*ord.Document{doc} 3552 }, 3553 }, { 3554 Name: "Missing `Extensible` field when `policyLevel` is sap partner for API", 3555 DocumentProvider: func() []*ord.Document { 3556 doc := fixORDDocument() 3557 doc.APIResources[0].Extensible = nil 3558 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3559 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3560 3561 return []*ord.Document{doc} 3562 }, 3563 }, { 3564 Name: "Invalid `Extensible` field due to empty json object for API", 3565 DocumentProvider: func() []*ord.Document { 3566 doc := fixORDDocument() 3567 doc.APIResources[0].Extensible = json.RawMessage(`{}`) 3568 3569 return []*ord.Document{doc} 3570 }, 3571 }, { 3572 Name: "Invalid `Extensible` field due to invalid json for API", 3573 DocumentProvider: func() []*ord.Document { 3574 doc := fixORDDocument() 3575 doc.APIResources[0].Extensible = json.RawMessage(invalidExtensibleDueToInvalidJSON) 3576 3577 return []*ord.Document{doc} 3578 }, 3579 }, { 3580 Name: "Missing `supported` field in the `extensible` object for API", 3581 DocumentProvider: func() []*ord.Document { 3582 doc := fixORDDocument() 3583 doc.APIResources[0].Extensible = json.RawMessage(invalidExtensibleDueToNoSupportedProperty) 3584 3585 return []*ord.Document{doc} 3586 }, 3587 }, { 3588 Name: "Invalid `supported` field type in the `extensible` object for API", 3589 DocumentProvider: func() []*ord.Document { 3590 doc := fixORDDocument() 3591 doc.APIResources[0].Extensible = json.RawMessage(invalidExtensibleDueToInvalidSupportedType) 3592 3593 return []*ord.Document{doc} 3594 }, 3595 }, { 3596 Name: "Invalid `supported` field value in the `extensible` object for API", 3597 DocumentProvider: func() []*ord.Document { 3598 doc := fixORDDocument() 3599 doc.APIResources[0].Extensible = json.RawMessage(invalidExtensibleDueToInvalidSupportedValue) 3600 3601 return []*ord.Document{doc} 3602 }, 3603 }, { 3604 Name: "Missing `description` field when `supported` has an `automatic` value for API", 3605 DocumentProvider: func() []*ord.Document { 3606 doc := fixORDDocument() 3607 doc.APIResources[0].Extensible = json.RawMessage(invalidExtensibleDueToSupportedAutomaticAndNoDescriptionProperty) 3608 3609 return []*ord.Document{doc} 3610 }, 3611 }, { 3612 Name: "Missing `description` field when `supported` has a `manual` value for API", 3613 DocumentProvider: func() []*ord.Document { 3614 doc := fixORDDocument() 3615 doc.APIResources[0].Extensible = json.RawMessage(invalidExtensibleDueToSupportedManualAndNoDescriptionProperty) 3616 3617 return []*ord.Document{doc} 3618 }, 3619 }, { 3620 Name: "Empty `description` field when `supported` has a `manual` value for API", 3621 DocumentProvider: func() []*ord.Document { 3622 doc := fixORDDocument() 3623 doc.APIResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "manual", "")) 3624 3625 return []*ord.Document{doc} 3626 }, 3627 }, { 3628 Name: "Empty `description` field when `supported` has a `automatic` value for API", 3629 DocumentProvider: func() []*ord.Document { 3630 doc := fixORDDocument() 3631 doc.APIResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "automatic", "")) 3632 3633 return []*ord.Document{doc} 3634 }, 3635 }, { 3636 Name: "Invalid `description` field with exceeding length when `supported` has a `manual` value for API", 3637 DocumentProvider: func() []*ord.Document { 3638 doc := fixORDDocument() 3639 doc.APIResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "manual", invalidDescriptionFieldWithExceedingMaxLength)) 3640 3641 return []*ord.Document{doc} 3642 }, 3643 }, { 3644 Name: "Invalid `description` field with exceeding length when `supported` has a `automatic` value for API", 3645 DocumentProvider: func() []*ord.Document { 3646 doc := fixORDDocument() 3647 doc.APIResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "automatic", invalidDescriptionFieldWithExceedingMaxLength)) 3648 3649 return []*ord.Document{doc} 3650 }, 3651 }, { 3652 Name: "Valid `WSDL V1` and `WSDL V2` definitions when APIResources has policyLevel `sap` and apiProtocol is `soap-inbound`", 3653 DocumentProvider: func() []*ord.Document { 3654 doc := fixORDDocument() 3655 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3656 *doc.APIResources[0].APIProtocol = ord.APIProtocolSoapInbound 3657 *doc.APIResources[1].APIProtocol = ord.APIProtocolSoapInbound 3658 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeWsdlV1 3659 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3660 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeWsdlV1 3661 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatApplicationXML 3662 doc.APIResources[1].ResourceDefinitions[0].Type = model.APISpecTypeWsdlV2 3663 doc.APIResources[1].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3664 3665 return []*ord.Document{doc} 3666 }, 3667 ExpectedToBeValid: true, 3668 }, { 3669 Name: "Valid `WSDL V1` and `WSDL V2` definitions when APIResources has policyLevel `sap-partner` and apiProtocol is `soap-inbound`", 3670 DocumentProvider: func() []*ord.Document { 3671 doc := fixORDDocument() 3672 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3673 *doc.APIResources[0].APIProtocol = ord.APIProtocolSoapInbound 3674 *doc.APIResources[1].APIProtocol = ord.APIProtocolSoapInbound 3675 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3676 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeWsdlV1 3677 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3678 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeWsdlV1 3679 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatApplicationXML 3680 doc.APIResources[1].ResourceDefinitions[0].Type = model.APISpecTypeWsdlV2 3681 doc.APIResources[1].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3682 3683 return []*ord.Document{doc} 3684 }, 3685 ExpectedToBeValid: true, 3686 }, { 3687 Name: "Valid `WSDL V1` and `WSDL V2` definitions when APIResources has policyLevel `sap` and apiProtocol is `soap-outbound`", 3688 DocumentProvider: func() []*ord.Document { 3689 doc := fixORDDocument() 3690 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3691 *doc.APIResources[0].APIProtocol = ord.APIProtocolSoapOutbound 3692 *doc.APIResources[1].APIProtocol = ord.APIProtocolSoapOutbound 3693 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeWsdlV1 3694 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3695 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeWsdlV1 3696 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatApplicationXML 3697 doc.APIResources[1].ResourceDefinitions[0].Type = model.APISpecTypeWsdlV2 3698 doc.APIResources[1].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3699 3700 return []*ord.Document{doc} 3701 }, 3702 ExpectedToBeValid: true, 3703 }, { 3704 Name: "Valid `SAP RFC Metadata` definitions when APIResources has policyLevel `sap` and apiProtocol is `sap-rfc`", 3705 DocumentProvider: func() []*ord.Document { 3706 doc := fixORDDocument() 3707 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3708 *doc.APIResources[0].APIProtocol = ord.APIProtocolSapRfc 3709 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeRfcMetadata 3710 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3711 3712 return []*ord.Document{doc} 3713 }, 3714 ExpectedToBeValid: true, 3715 }, { 3716 Name: "Valid `SAP RFC Metadata` definitions when APIResources has policyLevel `sap-partner` and apiProtocol is `sap-rfc`", 3717 DocumentProvider: func() []*ord.Document { 3718 doc := fixORDDocument() 3719 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3720 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3721 *doc.APIResources[0].APIProtocol = ord.APIProtocolSapRfc 3722 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeRfcMetadata 3723 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3724 3725 return []*ord.Document{doc} 3726 }, 3727 ExpectedToBeValid: true, 3728 }, { 3729 Name: "Missing `WSDL V1` or `WSDL V2` definition when APIResources has policyLevel `sap` and apiProtocol is `soap-inbound`", 3730 DocumentProvider: func() []*ord.Document { 3731 doc := fixORDDocument() 3732 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3733 *doc.APIResources[0].APIProtocol = ord.APIProtocolSoapInbound 3734 *doc.APIResources[1].APIProtocol = ord.APIProtocolSoapInbound 3735 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3736 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3737 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3738 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3739 doc.APIResources[1].ResourceDefinitions[0].Type = model.APISpecTypeEDMX 3740 doc.APIResources[1].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3741 return []*ord.Document{doc} 3742 }, 3743 }, { 3744 Name: "Missing `WSDL V1` or `WSDL V2` definition when APIResources has policyLevel `sap-partner` and apiProtocol is `soap-inbound`", 3745 DocumentProvider: func() []*ord.Document { 3746 doc := fixORDDocument() 3747 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3748 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3749 *doc.APIResources[0].APIProtocol = ord.APIProtocolSoapInbound 3750 *doc.APIResources[1].APIProtocol = ord.APIProtocolSoapInbound 3751 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3752 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3753 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3754 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3755 doc.APIResources[1].ResourceDefinitions[0].Type = model.APISpecTypeEDMX 3756 doc.APIResources[1].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3757 return []*ord.Document{doc} 3758 }, 3759 }, { 3760 Name: "Missing `WSDL V1` or `WSDL V2` definition when APIResources has policyLevel `sap` and apiProtocol is `soap-outbound`", 3761 DocumentProvider: func() []*ord.Document { 3762 doc := fixORDDocument() 3763 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3764 *doc.APIResources[0].APIProtocol = ord.APIProtocolSoapOutbound 3765 *doc.APIResources[1].APIProtocol = ord.APIProtocolSoapOutbound 3766 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3767 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3768 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3769 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3770 doc.APIResources[1].ResourceDefinitions[0].Type = model.APISpecTypeEDMX 3771 doc.APIResources[1].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3772 return []*ord.Document{doc} 3773 }, 3774 }, { 3775 Name: "Missing `WSDL V1` or `WSDL V2` definition when APIResources has policyLevel `sap-partner` and apiProtocol is `soap-outbound`", 3776 DocumentProvider: func() []*ord.Document { 3777 doc := fixORDDocument() 3778 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3779 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3780 *doc.APIResources[0].APIProtocol = ord.APIProtocolSoapOutbound 3781 *doc.APIResources[1].APIProtocol = ord.APIProtocolSoapOutbound 3782 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3783 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3784 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3785 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3786 doc.APIResources[1].ResourceDefinitions[0].Type = model.APISpecTypeEDMX 3787 doc.APIResources[1].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationXML 3788 return []*ord.Document{doc} 3789 }, 3790 }, { 3791 Name: "Missing `OpenAPI` and `EDMX` definitions when APIResources has policyLevel `sap` and apiProtocol is `odata-v2`", 3792 DocumentProvider: func() []*ord.Document { 3793 doc := fixORDDocument() 3794 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3795 *doc.APIResources[0].APIProtocol = ord.APIProtocolODataV2 3796 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3797 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3798 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3799 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3800 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3801 return []*ord.Document{doc} 3802 }, 3803 }, { 3804 Name: "Missing `OpenAPI` and `EDMX` definitions when APIResources has policyLevel `sap-partner` and apiProtocol is `odata-v2`", 3805 DocumentProvider: func() []*ord.Document { 3806 doc := fixORDDocument() 3807 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3808 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3809 *doc.APIResources[0].APIProtocol = ord.APIProtocolODataV2 3810 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3811 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3812 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3813 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3814 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3815 return []*ord.Document{doc} 3816 }, 3817 }, { 3818 Name: "Missing `OpenAPI` and `EDMX` definitions when APIResources has policyLevel `sap` and apiProtocol is `odata-v4`", 3819 DocumentProvider: func() []*ord.Document { 3820 doc := fixORDDocument() 3821 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3822 *doc.APIResources[0].APIProtocol = ord.APIProtocolODataV4 3823 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3824 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3825 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3826 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3827 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3828 return []*ord.Document{doc} 3829 }, 3830 }, { 3831 Name: "Missing `OpenAPI` and `EDMX` definitions when APIResources has policyLevel `sap-partner` and apiProtocol is `odata-v4`", 3832 DocumentProvider: func() []*ord.Document { 3833 doc := fixORDDocument() 3834 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3835 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3836 *doc.APIResources[0].APIProtocol = ord.APIProtocolODataV4 3837 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPIV2 3838 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatApplicationJSON 3839 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3840 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3841 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3842 return []*ord.Document{doc} 3843 }, 3844 }, { 3845 Name: "Missing `OpenAPI` definitions when APIResources has policyLevel `sap` and apiProtocol is `rest`", 3846 DocumentProvider: func() []*ord.Document { 3847 doc := fixORDDocument() 3848 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3849 *doc.APIResources[0].APIProtocol = ord.APIProtocolRest 3850 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeRaml 3851 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 3852 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3853 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3854 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3855 return []*ord.Document{doc} 3856 }, 3857 }, { 3858 Name: "Missing `OpenAPI` definitions when APIResources has policyLevel `sap-partner` and apiProtocol is `rest`", 3859 DocumentProvider: func() []*ord.Document { 3860 doc := fixORDDocument() 3861 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3862 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3863 *doc.APIResources[0].APIProtocol = ord.APIProtocolRest 3864 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeRaml 3865 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 3866 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3867 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3868 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3869 return []*ord.Document{doc} 3870 }, 3871 }, { 3872 Name: "Missing `SAP RFC` definitions when APIResources has policyLevel `sap` and apiProtocol is `sap-rfc-metadata-v1`", 3873 DocumentProvider: func() []*ord.Document { 3874 doc := fixORDDocument() 3875 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 3876 *doc.APIResources[0].APIProtocol = ord.APIProtocolSapRfc 3877 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeRaml 3878 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 3879 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3880 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3881 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3882 return []*ord.Document{doc} 3883 }, 3884 }, { 3885 Name: "Missing `SAP RFC` definitions when APIResources has policyLevel `sap-partner` and apiProtocol is `sap-rfc-metadata-v1`", 3886 DocumentProvider: func() []*ord.Document { 3887 doc := fixORDDocument() 3888 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3889 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3890 *doc.APIResources[0].APIProtocol = ord.APIProtocolSapRfc 3891 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeRaml 3892 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 3893 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeRaml 3894 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatTextYAML 3895 doc.APIResources[0].ResourceDefinitions[2] = &model.APIResourceDefinition{} 3896 return []*ord.Document{doc} 3897 }, 3898 }, { 3899 Name: "Missing `implementationStandard` when APIResources has apiProtocol `websocket`", 3900 DocumentProvider: func() []*ord.Document { 3901 doc := fixORDDocument() 3902 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3903 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3904 *doc.APIResources[0].APIProtocol = ord.APIProtocolWebsocket 3905 doc.APIResources[0].ImplementationStandard = nil 3906 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeCustom 3907 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeCustom 3908 return []*ord.Document{doc} 3909 }, 3910 }, { 3911 Name: "Wrong `type` when APIResources has apiProtocol `websocket`", 3912 DocumentProvider: func() []*ord.Document { 3913 doc := fixORDDocument() 3914 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3915 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3916 *doc.APIResources[0].APIProtocol = ord.APIProtocolWebsocket 3917 doc.APIResources[0].ImplementationStandard = str.Ptr("sap:cdi-api:v1") 3918 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeOpenAPI 3919 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeOpenAPI 3920 return []*ord.Document{doc} 3921 }, 3922 }, { 3923 Name: "Correct `type` when APIResources has apiProtocol `websocket`", 3924 DocumentProvider: func() []*ord.Document { 3925 doc := fixORDDocument() 3926 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3927 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3928 *doc.APIResources[0].APIProtocol = ord.APIProtocolWebsocket 3929 doc.APIResources[0].ImplementationStandard = str.Ptr("sap:cdi-api:v1") 3930 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeCustom 3931 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeCustom 3932 return []*ord.Document{doc} 3933 }, 3934 ExpectedToBeValid: true, 3935 }, { 3936 Name: "Wrong `type` in one of the ResourceDefinitions when APIResources has apiProtocol `websocket`", 3937 DocumentProvider: func() []*ord.Document { 3938 doc := fixORDDocument() 3939 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3940 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3941 *doc.APIResources[0].APIProtocol = ord.APIProtocolWebsocket 3942 doc.APIResources[0].ImplementationStandard = str.Ptr("sap:cdi-api:v1") 3943 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeCustom 3944 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeOpenAPI 3945 return []*ord.Document{doc} 3946 }, 3947 }, { 3948 Name: "Correct `type` when APIResources has apiProtocol `sap-sql-api-v1`", 3949 DocumentProvider: func() []*ord.Document { 3950 doc := fixORDDocument() 3951 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3952 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3953 *doc.APIResources[0].APIProtocol = ord.APIProtocolSAPSQLAPIV1 3954 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeCustom 3955 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 3956 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeSQLAPIDefinitionV1 3957 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatApplicationJSON 3958 return []*ord.Document{doc} 3959 }, 3960 ExpectedToBeValid: true, 3961 }, { 3962 Name: "Wrong `type` when APIResources has apiProtocol `sap-sql-api-v1`", 3963 DocumentProvider: func() []*ord.Document { 3964 doc := fixORDDocument() 3965 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 3966 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 3967 *doc.APIResources[0].APIProtocol = ord.APIProtocolSAPSQLAPIV1 3968 doc.APIResources[0].ResourceDefinitions[0].Type = model.APISpecTypeCsdl 3969 doc.APIResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 3970 doc.APIResources[0].ResourceDefinitions[1].Type = model.APISpecTypeSQLAPIDefinitionV1 3971 doc.APIResources[0].ResourceDefinitions[1].MediaType = model.SpecFormatApplicationJSON 3972 return []*ord.Document{doc} 3973 }, 3974 }, 3975 // Test invalid entity relations 3976 3977 { 3978 Name: "API has a reference to an unknown Package", 3979 DocumentProvider: func() []*ord.Document { 3980 doc := fixORDDocument() 3981 doc.APIResources[0].OrdPackageID = str.Ptr(unknownPackageOrdID) 3982 3983 return []*ord.Document{doc} 3984 }, 3985 }, { 3986 Name: "API has a reference to an unknown Bundle", 3987 DocumentProvider: func() []*ord.Document { 3988 doc := fixORDDocument() 3989 doc.ConsumptionBundles = fixBundleCreateInput() 3990 doc.APIResources[0].PartOfConsumptionBundles = fixAPIPartOfConsumptionBundles() 3991 doc.APIResources[0].PartOfConsumptionBundles[0].BundleOrdID = unknownBundleOrdID 3992 3993 return []*ord.Document{doc} 3994 }, 3995 }, { 3996 Name: "API has a reference to an unknown Product", 3997 DocumentProvider: func() []*ord.Document { 3998 doc := fixORDDocument() 3999 doc.APIResources[0].PartOfProducts = json.RawMessage(fmt.Sprintf(`["%s"]`, unknownProductOrdID)) 4000 4001 return []*ord.Document{doc} 4002 }, 4003 }, 4004 } 4005 4006 for _, test := range tests { 4007 t.Run(test.Name, func(t *testing.T) { 4008 docs := ord.Documents{test.DocumentProvider()[0]} 4009 resourcesFromDB := ord.ResourcesFromDB{ 4010 APIs: apisFromDB, 4011 Events: eventsFromDB, 4012 Packages: pkgsFromDB, 4013 Bundles: bndlsFromDB, 4014 } 4015 4016 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 4017 4018 if test.AfterTest != nil { 4019 test.AfterTest() 4020 } 4021 4022 if test.ExpectedToBeValid { 4023 require.NoError(t, err) 4024 } else { 4025 require.Error(t, err) 4026 } 4027 }) 4028 } 4029 } 4030 4031 func TestDocuments_ValidateEvent(t *testing.T) { 4032 var tests = []struct { 4033 Name string 4034 DocumentProvider func() []*ord.Document 4035 ExpectedToBeValid bool 4036 AfterTest func() 4037 }{ 4038 { 4039 Name: "Missing `ordID` field for Event", 4040 DocumentProvider: func() []*ord.Document { 4041 doc := fixORDDocument() 4042 doc.EventResources[0].OrdID = nil 4043 4044 return []*ord.Document{doc} 4045 }, 4046 }, { 4047 Name: "Invalid `ordID` field for Event", 4048 DocumentProvider: func() []*ord.Document { 4049 doc := fixORDDocument() 4050 doc.EventResources[0].OrdID = str.Ptr(invalidOrdID) 4051 4052 return []*ord.Document{doc} 4053 }, 4054 }, { 4055 Name: "Missing `title` field for Event", 4056 DocumentProvider: func() []*ord.Document { 4057 doc := fixORDDocument() 4058 doc.EventResources[0].Name = "" 4059 4060 return []*ord.Document{doc} 4061 }, 4062 }, { 4063 Name: "Missing `localTenantID` field for Event", 4064 DocumentProvider: func() []*ord.Document { 4065 doc := fixORDDocument() 4066 doc.EventResources[0].LocalTenantID = nil 4067 4068 return []*ord.Document{doc} 4069 }, 4070 ExpectedToBeValid: true, 4071 }, { 4072 Name: "Exceeded length of `localTenantID` field for Event", 4073 DocumentProvider: func() []*ord.Document { 4074 doc := fixORDDocument() 4075 doc.EventResources[0].LocalTenantID = str.Ptr(strings.Repeat("a", invalidLocalTenantIDLength)) 4076 4077 return []*ord.Document{doc} 4078 }, 4079 }, { 4080 Name: "Invalid empty `localTenantID` field for Event", 4081 DocumentProvider: func() []*ord.Document { 4082 doc := fixORDDocument() 4083 doc.EventResources[0].LocalTenantID = str.Ptr("") 4084 4085 return []*ord.Document{doc} 4086 }, 4087 }, { 4088 Name: "Missing `shortDescription` field for Event", 4089 DocumentProvider: func() []*ord.Document { 4090 doc := fixORDDocument() 4091 doc.EventResources[0].ShortDescription = nil 4092 4093 return []*ord.Document{doc} 4094 }, 4095 }, { 4096 Name: "Exceeded length of `shortDescription` field for Event", 4097 DocumentProvider: func() []*ord.Document { 4098 doc := fixORDDocument() 4099 doc.EventResources[0].ShortDescription = str.Ptr(strings.Repeat("a", invalidShortDescriptionLength)) 4100 4101 return []*ord.Document{doc} 4102 }, 4103 }, { 4104 Name: "Invalid empty `shortDescription` field for Event", 4105 DocumentProvider: func() []*ord.Document { 4106 doc := fixORDDocument() 4107 doc.EventResources[0].ShortDescription = str.Ptr("") 4108 4109 return []*ord.Document{doc} 4110 }, 4111 }, { 4112 Name: "New lines in `shortDescription` field for Event", 4113 DocumentProvider: func() []*ord.Document { 4114 doc := fixORDDocument() 4115 doc.EventResources[0].ShortDescription = str.Ptr(`newLine\n`) 4116 4117 return []*ord.Document{doc} 4118 }, 4119 }, { 4120 Name: "Missing `description` field for Event", 4121 DocumentProvider: func() []*ord.Document { 4122 doc := fixORDDocument() 4123 doc.EventResources[0].Description = nil 4124 4125 return []*ord.Document{doc} 4126 }, 4127 }, { 4128 Name: "Invalid `description` field with exceeding length for Event", 4129 DocumentProvider: func() []*ord.Document { 4130 doc := fixORDDocument() 4131 doc.EventResources[0].Description = str.Ptr(invalidDescriptionFieldWithExceedingMaxLength) 4132 4133 return []*ord.Document{doc} 4134 }, 4135 }, { 4136 Name: "Missing `version` field for Event", 4137 DocumentProvider: func() []*ord.Document { 4138 doc := fixORDDocument() 4139 doc.EventResources[0].VersionInput.Value = "" 4140 4141 return []*ord.Document{doc} 4142 }, 4143 }, { 4144 Name: "Not incremented `version` field when resource definition's URL has changed for Event", 4145 DocumentProvider: func() []*ord.Document { 4146 doc := fixORDDocument() 4147 doc.EventResources[0].ResourceDefinitions[0].URL = "http://newurl.com/odata/$metadata" 4148 4149 newHash, err := ord.HashObject(doc.EventResources[0]) 4150 require.NoError(t, err) 4151 4152 resourceHashes[event1ORDID] = newHash 4153 4154 return []*ord.Document{doc} 4155 }, 4156 AfterTest: func() { 4157 resourceHashes = fixResourceHashes() 4158 }, 4159 }, { 4160 Name: "Not incremented `version` field when resource definition's MediaType has changed for Event", 4161 DocumentProvider: func() []*ord.Document { 4162 doc := fixORDDocument() 4163 doc.EventResources[0].ResourceDefinitions[0].MediaType = model.SpecFormatTextYAML 4164 4165 newHash, err := ord.HashObject(doc.EventResources[0]) 4166 require.NoError(t, err) 4167 4168 resourceHashes[event1ORDID] = newHash 4169 4170 return []*ord.Document{doc} 4171 }, 4172 AfterTest: func() { 4173 resourceHashes = fixResourceHashes() 4174 }, 4175 }, { 4176 Name: "Not incremented `version` field when resource definition's Type has changed for Event", 4177 DocumentProvider: func() []*ord.Document { 4178 doc := fixORDDocument() 4179 doc.EventResources[0].ResourceDefinitions[0].Type = model.EventSpecTypeCustom 4180 doc.EventResources[0].ResourceDefinitions[0].CustomType = "sap:custom-definition-format:v1" 4181 4182 newHash, err := ord.HashObject(doc.EventResources[0]) 4183 require.NoError(t, err) 4184 4185 resourceHashes[event1ORDID] = newHash 4186 4187 return []*ord.Document{doc} 4188 }, 4189 AfterTest: func() { 4190 resourceHashes = fixResourceHashes() 4191 }, 4192 }, { 4193 Name: "Not incremented `version` field when resource has changed for Event", 4194 DocumentProvider: func() []*ord.Document { 4195 doc := fixORDDocument() 4196 doc.EventResources[0].Industry = json.RawMessage(`["Utilities"]`) 4197 4198 newHash, err := ord.HashObject(doc.EventResources[0]) 4199 require.NoError(t, err) 4200 4201 resourceHashes[event1ORDID] = newHash 4202 4203 return []*ord.Document{doc} 4204 }, 4205 AfterTest: func() { 4206 resourceHashes = fixResourceHashes() 4207 }, 4208 }, { 4209 Name: "Valid incremented `version` field when resource definition has changed for Event", 4210 DocumentProvider: func() []*ord.Document { 4211 doc := fixORDDocument() 4212 doc.EventResources[0].ResourceDefinitions[0].Type = model.EventSpecTypeCustom 4213 doc.EventResources[0].ResourceDefinitions[0].CustomType = "sap:custom-definition-format:v1" 4214 doc.EventResources[0].VersionInput.Value = "2.1.4" 4215 4216 hash, err := ord.HashObject(doc.EventResources[0]) 4217 require.NoError(t, err) 4218 4219 resourceHashes[event1ORDID] = hash 4220 4221 return []*ord.Document{doc} 4222 }, 4223 AfterTest: func() { 4224 resourceHashes = fixResourceHashes() 4225 }, 4226 ExpectedToBeValid: true, 4227 }, { 4228 Name: "Invalid `version` field for Event", 4229 DocumentProvider: func() []*ord.Document { 4230 doc := fixORDDocument() 4231 doc.EventResources[0].VersionInput.Value = invalidVersion 4232 4233 return []*ord.Document{doc} 4234 }, 4235 }, { 4236 Name: "Missing field `version` of field `changeLogEntries` for Event", 4237 DocumentProvider: func() []*ord.Document { 4238 doc := fixORDDocument() 4239 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToMissingVersion) 4240 4241 return []*ord.Document{doc} 4242 }, 4243 }, { 4244 Name: "Invalid field `version` of field `changeLogEntries` for Event", 4245 DocumentProvider: func() []*ord.Document { 4246 doc := fixORDDocument() 4247 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongVersion) 4248 4249 return []*ord.Document{doc} 4250 }, 4251 }, { 4252 Name: "Missing field `releaseStatus` of field `changeLogEntries` for Event", 4253 DocumentProvider: func() []*ord.Document { 4254 doc := fixORDDocument() 4255 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToMissingReleaseStatus) 4256 4257 return []*ord.Document{doc} 4258 }, 4259 }, { 4260 Name: "Invalid field `releaseStatus` of field `changeLogEntries` for Event", 4261 DocumentProvider: func() []*ord.Document { 4262 doc := fixORDDocument() 4263 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongReleaseStatus) 4264 4265 return []*ord.Document{doc} 4266 }, 4267 }, { 4268 Name: "Missing field `date` of field `changeLogEntries` for Event", 4269 DocumentProvider: func() []*ord.Document { 4270 doc := fixORDDocument() 4271 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToMissingDate) 4272 4273 return []*ord.Document{doc} 4274 }, 4275 }, { 4276 Name: "Invalid field `date` of field `changeLogEntries` for Event", 4277 DocumentProvider: func() []*ord.Document { 4278 doc := fixORDDocument() 4279 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongDate) 4280 4281 return []*ord.Document{doc} 4282 }, 4283 }, { 4284 Name: "Invalid field `url` of field `changeLogEntries` for Event", 4285 DocumentProvider: func() []*ord.Document { 4286 doc := fixORDDocument() 4287 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidChangeLogEntriesDueToWrongURL) 4288 4289 return []*ord.Document{doc} 4290 }, 4291 }, { 4292 Name: "Invalid empty field `description` of field `changeLogEntries` for Event", 4293 DocumentProvider: func() []*ord.Document { 4294 doc := fixORDDocument() 4295 doc.EventResources[0].ChangeLogEntries = json.RawMessage(fmt.Sprintf(invalidChangeLogEntriesDueToInvalidLengthOfDescription, "")) 4296 4297 return []*ord.Document{doc} 4298 }, 4299 }, { 4300 Name: "Invalid field `description` with exceeding length of field `changeLogEntries` for Event", 4301 DocumentProvider: func() []*ord.Document { 4302 doc := fixORDDocument() 4303 doc.EventResources[0].ChangeLogEntries = json.RawMessage(fmt.Sprintf(invalidChangeLogEntriesDueToInvalidLengthOfDescription, invalidDescriptionFieldWithExceedingMaxLength)) 4304 4305 return []*ord.Document{doc} 4306 }, 4307 }, { 4308 Name: "Invalid `changeLogEntries` field when it is invalid JSON for Event", 4309 DocumentProvider: func() []*ord.Document { 4310 doc := fixORDDocument() 4311 doc.EventResources[0].ChangeLogEntries = json.RawMessage(invalidJSON) 4312 4313 return []*ord.Document{doc} 4314 }, 4315 }, { 4316 Name: "Invalid `changeLogEntries` field when it isn't a JSON array for Event", 4317 DocumentProvider: func() []*ord.Document { 4318 doc := fixORDDocument() 4319 doc.EventResources[0].ChangeLogEntries = json.RawMessage("{}") 4320 4321 return []*ord.Document{doc} 4322 }, 4323 }, { 4324 Name: "Valid `changeLogEntries` field when it is an empty JSON array for Event", 4325 DocumentProvider: func() []*ord.Document { 4326 doc := fixORDDocument() 4327 doc.EventResources[0].ChangeLogEntries = json.RawMessage("[]") 4328 4329 return []*ord.Document{doc} 4330 }, 4331 ExpectedToBeValid: true, 4332 }, { 4333 Name: "Missing `partOfPackage` field for Event", 4334 DocumentProvider: func() []*ord.Document { 4335 doc := fixORDDocument() 4336 doc.EventResources[0].OrdPackageID = nil 4337 4338 return []*ord.Document{doc} 4339 }, 4340 }, { 4341 Name: "Invalid `partOfPackage` field for Event", 4342 DocumentProvider: func() []*ord.Document { 4343 doc := fixORDDocument() 4344 doc.EventResources[0].OrdPackageID = str.Ptr(invalidOrdID) 4345 4346 return []*ord.Document{doc} 4347 }, 4348 }, { 4349 Name: "Missing `visibility` field for Event", 4350 DocumentProvider: func() []*ord.Document { 4351 doc := fixORDDocument() 4352 doc.EventResources[0].Visibility = nil 4353 4354 return []*ord.Document{doc} 4355 }, 4356 }, { 4357 Name: "Invalid `visibility` field for Event", 4358 DocumentProvider: func() []*ord.Document { 4359 doc := fixORDDocument() 4360 doc.EventResources[0].Visibility = str.Ptr("wrongVisibility") 4361 4362 return []*ord.Document{doc} 4363 }, 4364 }, { 4365 Name: "Missing `title` field in `Links` for Event", 4366 DocumentProvider: func() []*ord.Document { 4367 doc := fixORDDocument() 4368 doc.EventResources[0].Links = json.RawMessage(invalidLinkDueToMissingTitle) 4369 4370 return []*ord.Document{doc} 4371 }, 4372 }, { 4373 Name: "Missing `url` field in `Links` for Event", 4374 DocumentProvider: func() []*ord.Document { 4375 doc := fixORDDocument() 4376 doc.EventResources[0].Links = json.RawMessage(invalidLinkDueToMissingURL) 4377 4378 return []*ord.Document{doc} 4379 }, 4380 }, { 4381 Name: "Invalid `url` field in `Links` for Event", 4382 DocumentProvider: func() []*ord.Document { 4383 doc := fixORDDocument() 4384 doc.EventResources[0].Links = json.RawMessage(invalidLinkDueToWrongURL) 4385 4386 return []*ord.Document{doc} 4387 }, 4388 }, { 4389 Name: "Invalid `description` field with exceeding length in `Links` for Event", 4390 DocumentProvider: func() []*ord.Document { 4391 doc := fixORDDocument() 4392 doc.EventResources[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, invalidDescriptionFieldWithExceedingMaxLength)) 4393 4394 return []*ord.Document{doc} 4395 }, 4396 }, { 4397 Name: "Invalid empty `description` field in `Links` for Event", 4398 DocumentProvider: func() []*ord.Document { 4399 doc := fixORDDocument() 4400 doc.EventResources[0].Links = json.RawMessage(fmt.Sprintf(invalidLinkDueToInvalidLengthOfDescription, "")) 4401 4402 return []*ord.Document{doc} 4403 }, 4404 }, { 4405 Name: "Invalid `links` field when it is invalid JSON for Event", 4406 DocumentProvider: func() []*ord.Document { 4407 doc := fixORDDocument() 4408 doc.EventResources[0].Links = json.RawMessage(invalidJSON) 4409 4410 return []*ord.Document{doc} 4411 }, 4412 }, { 4413 Name: "Invalid `links` field when it isn't a JSON array for Event", 4414 DocumentProvider: func() []*ord.Document { 4415 doc := fixORDDocument() 4416 doc.EventResources[0].Links = json.RawMessage("{}") 4417 4418 return []*ord.Document{doc} 4419 }, 4420 }, { 4421 Name: "Valid `links` field when it is an empty JSON array for Event", 4422 DocumentProvider: func() []*ord.Document { 4423 doc := fixORDDocument() 4424 doc.EventResources[0].Links = json.RawMessage("[]") 4425 4426 return []*ord.Document{doc} 4427 }, 4428 ExpectedToBeValid: true, 4429 }, { 4430 Name: "Invalid element of `partOfProducts` array field for Event", 4431 DocumentProvider: func() []*ord.Document { 4432 doc := fixORDDocument() 4433 doc.EventResources[0].PartOfProducts = json.RawMessage(invalidPartOfProductsElement) 4434 4435 return []*ord.Document{doc} 4436 }, 4437 }, { 4438 Name: "Valid `partOfProducts` field when the JSON array is empty for Event", 4439 DocumentProvider: func() []*ord.Document { 4440 doc := fixORDDocument() 4441 doc.EventResources[0].PartOfProducts = json.RawMessage("[]") 4442 4443 return []*ord.Document{doc} 4444 }, 4445 ExpectedToBeValid: true, 4446 }, { 4447 Name: "Invalid `partOfProducts` field when it is invalid JSON for Event", 4448 DocumentProvider: func() []*ord.Document { 4449 doc := fixORDDocument() 4450 doc.EventResources[0].PartOfProducts = json.RawMessage(invalidJSON) 4451 4452 return []*ord.Document{doc} 4453 }, 4454 }, { 4455 Name: "Invalid `partOfProducts` field when it isn't a JSON array for Event", 4456 DocumentProvider: func() []*ord.Document { 4457 doc := fixORDDocument() 4458 doc.EventResources[0].PartOfProducts = json.RawMessage("{}") 4459 4460 return []*ord.Document{doc} 4461 }, 4462 }, { 4463 Name: "Invalid `partOfProducts` field when it contains non string value for Event", 4464 DocumentProvider: func() []*ord.Document { 4465 doc := fixORDDocument() 4466 doc.EventResources[0].PartOfProducts = json.RawMessage(invalidPartOfProductsIntegerElement) 4467 4468 return []*ord.Document{doc} 4469 }, 4470 }, { 4471 Name: "Valid missing `resourceDefinitions` field for Event when `policyLevel` is sap and `visibility` is private", 4472 DocumentProvider: func() []*ord.Document { 4473 doc := fixORDDocument() 4474 doc.EventResources[0].ResourceDefinitions = nil 4475 doc.EventResources[0].Visibility = str.Ptr(ord.APIVisibilityPrivate) 4476 doc.Packages[0].PolicyLevel = policyLevel 4477 4478 return []*ord.Document{doc} 4479 }, 4480 ExpectedToBeValid: true, 4481 }, { 4482 Name: "Missing `resourceDefinitions` field for Event", 4483 DocumentProvider: func() []*ord.Document { 4484 doc := fixORDDocument() 4485 doc.EventResources[0].ResourceDefinitions = nil 4486 4487 return []*ord.Document{doc} 4488 }, 4489 }, { 4490 Name: "Missing field `type` of `resourceDefinitions` field for Event", 4491 DocumentProvider: func() []*ord.Document { 4492 doc := fixORDDocument() 4493 doc.EventResources[0].ResourceDefinitions[0].Type = "" 4494 4495 return []*ord.Document{doc} 4496 }, 4497 }, { 4498 Name: "Invalid field `type` of `resourceDefinitions` field for Event", 4499 DocumentProvider: func() []*ord.Document { 4500 doc := fixORDDocument() 4501 doc.EventResources[0].ResourceDefinitions[0].Type = invalidType 4502 4503 return []*ord.Document{doc} 4504 }, 4505 }, { 4506 Name: "Field `type` value is not `custom` when field `customType` is provided for `resourceDefinitions` field for Event", 4507 DocumentProvider: func() []*ord.Document { 4508 doc := fixORDDocument() 4509 doc.EventResources[0].ResourceDefinitions[0].CustomType = "test:test:v1" 4510 4511 return []*ord.Document{doc} 4512 }, 4513 }, { 4514 Name: "Invalid `customType` value when field `type` has value `custom`for `resourceDefinitions` field for Event", 4515 DocumentProvider: func() []*ord.Document { 4516 doc := fixORDDocument() 4517 doc.EventResources[0].ResourceDefinitions[0].Type = "custom" 4518 doc.EventResources[0].ResourceDefinitions[0].CustomType = invalidCustomType 4519 4520 return []*ord.Document{doc} 4521 }, 4522 }, { 4523 Name: "Missing field `mediaType` of `resourceDefinitions` field for Event", 4524 DocumentProvider: func() []*ord.Document { 4525 doc := fixORDDocument() 4526 doc.EventResources[0].ResourceDefinitions[0].MediaType = "" 4527 4528 return []*ord.Document{doc} 4529 }, 4530 }, { 4531 Name: "Invalid field `mediaType` of `resourceDefinitions` field for Event", 4532 DocumentProvider: func() []*ord.Document { 4533 doc := fixORDDocument() 4534 doc.EventResources[0].ResourceDefinitions[0].MediaType = invalidMediaType 4535 4536 return []*ord.Document{doc} 4537 }, 4538 }, { 4539 Name: "Missing field `url` of `resourceDefinitions` field for Event", 4540 DocumentProvider: func() []*ord.Document { 4541 doc := fixORDDocument() 4542 doc.EventResources[0].ResourceDefinitions[0].URL = "" 4543 4544 return []*ord.Document{doc} 4545 }, 4546 }, { 4547 Name: "Invalid field `url` of `resourceDefinitions` field for Event", 4548 DocumentProvider: func() []*ord.Document { 4549 doc := fixORDDocument() 4550 doc.EventResources[0].ResourceDefinitions[0].URL = invalidURL 4551 4552 return []*ord.Document{doc} 4553 }, 4554 }, { 4555 Name: "Missing field `accessStrategies` of `resourceDefinitions` field for Event", 4556 DocumentProvider: func() []*ord.Document { 4557 doc := fixORDDocument() 4558 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy = nil 4559 4560 return []*ord.Document{doc} 4561 }, 4562 }, { 4563 Name: "Missing field `type` for `accessStrategies` of `resourceDefinitions` field for Event", 4564 DocumentProvider: func() []*ord.Document { 4565 doc := fixORDDocument() 4566 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "" 4567 4568 return []*ord.Document{doc} 4569 }, 4570 }, { 4571 Name: "Invalid field `type` for `accessStrategies` of `resourceDefinitions` field for Event", 4572 DocumentProvider: func() []*ord.Document { 4573 doc := fixORDDocument() 4574 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = invalidType 4575 4576 return []*ord.Document{doc} 4577 }, 4578 }, { 4579 Name: "Invalid field `customType` when field `type` is not `custom` for `accessStrategies` of `resourceDefinitions` field for Event", 4580 DocumentProvider: func() []*ord.Document { 4581 doc := fixORDDocument() 4582 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "open" 4583 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomType = "foo" 4584 4585 return []*ord.Document{doc} 4586 }, 4587 }, { 4588 Name: "Invalid field `customType` when field `type` is `custom` for `accessStrategies` of `resourceDefinitions` field for Event", 4589 DocumentProvider: func() []*ord.Document { 4590 doc := fixORDDocument() 4591 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "custom" 4592 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomType = invalidCustomType 4593 4594 return []*ord.Document{doc} 4595 }, 4596 }, { 4597 Name: "Field `type` is not `custom` when `customType` is valid for `accessStrategies` of `resourceDefinitions` field for Event", 4598 DocumentProvider: func() []*ord.Document { 4599 doc := fixORDDocument() 4600 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "open" 4601 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomType = "sap:custom-definition-format:v1" 4602 4603 return []*ord.Document{doc} 4604 }, 4605 }, { 4606 Name: "Invalid field `customDescription` when field `type` is not `custom` for `accessStrategies` of `resourceDefinitions` field for Event", 4607 DocumentProvider: func() []*ord.Document { 4608 doc := fixORDDocument() 4609 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "open" 4610 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomDescription = "foo" 4611 4612 return []*ord.Document{doc} 4613 }, 4614 }, { 4615 Name: "Invalid field `customDescription` with exceeding length when field `type` is `custom` for `accessStrategies` of `resourceDefinitions` field for Event", 4616 DocumentProvider: func() []*ord.Document { 4617 doc := fixORDDocument() 4618 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].Type = "custom" 4619 doc.EventResources[0].ResourceDefinitions[0].AccessStrategy[0].CustomDescription = invalidDescriptionFieldWithExceedingMaxLength 4620 4621 return []*ord.Document{doc} 4622 }, 4623 }, { 4624 Name: "Invalid value for `tags` field for Event", 4625 DocumentProvider: func() []*ord.Document { 4626 doc := fixORDDocument() 4627 doc.EventResources[0].Tags = json.RawMessage(invalidTagsValue) 4628 4629 return []*ord.Document{doc} 4630 }, 4631 }, { 4632 Name: "Invalid `tags` field when it is invalid JSON for Event", 4633 DocumentProvider: func() []*ord.Document { 4634 doc := fixORDDocument() 4635 doc.EventResources[0].Tags = json.RawMessage(invalidJSON) 4636 4637 return []*ord.Document{doc} 4638 }, 4639 }, { 4640 Name: "Invalid `tags` field when it isn't a JSON array for Event", 4641 DocumentProvider: func() []*ord.Document { 4642 doc := fixORDDocument() 4643 doc.EventResources[0].Tags = json.RawMessage("{}") 4644 4645 return []*ord.Document{doc} 4646 }, 4647 }, { 4648 Name: "Valid `tags` field when the JSON array is empty for Event", 4649 DocumentProvider: func() []*ord.Document { 4650 doc := fixORDDocument() 4651 doc.EventResources[0].Tags = json.RawMessage("[]") 4652 4653 return []*ord.Document{doc} 4654 }, 4655 ExpectedToBeValid: true, 4656 }, { 4657 Name: "Invalid `tags` field when it contains non string value for Event", 4658 DocumentProvider: func() []*ord.Document { 4659 doc := fixORDDocument() 4660 doc.EventResources[0].Tags = json.RawMessage(invalidTagsValueIntegerElement) 4661 4662 return []*ord.Document{doc} 4663 }, 4664 }, { 4665 Name: "Invalid JSON `Labels` field for Event", 4666 DocumentProvider: func() []*ord.Document { 4667 doc := fixORDDocument() 4668 doc.EventResources[0].Labels = json.RawMessage(invalidJSON) 4669 4670 return []*ord.Document{doc} 4671 }, 4672 }, { 4673 Name: "Invalid JSON object `Labels` field for Event", 4674 DocumentProvider: func() []*ord.Document { 4675 doc := fixORDDocument() 4676 doc.EventResources[0].Labels = json.RawMessage(`[]`) 4677 4678 return []*ord.Document{doc} 4679 }, 4680 }, { 4681 Name: "`Labels` values are not array for Event", 4682 DocumentProvider: func() []*ord.Document { 4683 doc := fixORDDocument() 4684 doc.EventResources[0].Labels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 4685 4686 return []*ord.Document{doc} 4687 }, 4688 }, { 4689 Name: "`Labels` values are not array of strings for Event", 4690 DocumentProvider: func() []*ord.Document { 4691 doc := fixORDDocument() 4692 doc.EventResources[0].Labels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 4693 4694 return []*ord.Document{doc} 4695 }, 4696 }, { 4697 Name: "Invalid key for JSON `Labels` field for Event", 4698 DocumentProvider: func() []*ord.Document { 4699 doc := fixORDDocument() 4700 doc.EventResources[0].Labels = json.RawMessage(invalidLabelsWhenKeyIsWrong) 4701 4702 return []*ord.Document{doc} 4703 }, 4704 }, { 4705 Name: "Invalid JSON object `DocumentationLabels` field for Event", 4706 DocumentProvider: func() []*ord.Document { 4707 doc := fixORDDocument() 4708 doc.EventResources[0].DocumentationLabels = json.RawMessage(`[]`) 4709 4710 return []*ord.Document{doc} 4711 }, 4712 }, { 4713 Name: "`DocumentationLabels` values are not array for Event", 4714 DocumentProvider: func() []*ord.Document { 4715 doc := fixORDDocument() 4716 doc.EventResources[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 4717 4718 return []*ord.Document{doc} 4719 }, 4720 }, { 4721 Name: "`DocumentationLabels` values are not array of strings for Event", 4722 DocumentProvider: func() []*ord.Document { 4723 doc := fixORDDocument() 4724 doc.EventResources[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 4725 4726 return []*ord.Document{doc} 4727 }, 4728 }, { 4729 Name: "Invalid value for `countries` field for Event", 4730 DocumentProvider: func() []*ord.Document { 4731 doc := fixORDDocument() 4732 doc.EventResources[0].Countries = json.RawMessage(invalidCountriesElement) 4733 4734 return []*ord.Document{doc} 4735 }, 4736 }, { 4737 Name: "Invalid `countries` field when it is invalid JSON for Event", 4738 DocumentProvider: func() []*ord.Document { 4739 doc := fixORDDocument() 4740 doc.EventResources[0].Countries = json.RawMessage(invalidJSON) 4741 4742 return []*ord.Document{doc} 4743 }, 4744 }, { 4745 Name: "Invalid `countries` field when it isn't a JSON array for Event", 4746 DocumentProvider: func() []*ord.Document { 4747 doc := fixORDDocument() 4748 doc.EventResources[0].Countries = json.RawMessage("{}") 4749 4750 return []*ord.Document{doc} 4751 }, 4752 }, { 4753 Name: "Valid `countries` field when the JSON array is empty for Event", 4754 DocumentProvider: func() []*ord.Document { 4755 doc := fixORDDocument() 4756 doc.EventResources[0].Countries = json.RawMessage("[]") 4757 4758 return []*ord.Document{doc} 4759 }, 4760 ExpectedToBeValid: true, 4761 }, { 4762 Name: "Invalid `countries` field when it contains non string value for Event", 4763 DocumentProvider: func() []*ord.Document { 4764 doc := fixORDDocument() 4765 doc.EventResources[0].Countries = json.RawMessage(invalidCountriesNonStringElement) 4766 4767 return []*ord.Document{doc} 4768 }, 4769 }, { 4770 Name: "Invalid value for `lineOfBusiness` field for Event", 4771 DocumentProvider: func() []*ord.Document { 4772 doc := fixORDDocument() 4773 doc.EventResources[0].LineOfBusiness = json.RawMessage(invalidLineOfBusinessElement) 4774 4775 return []*ord.Document{doc} 4776 }, 4777 }, { 4778 Name: "Invalid `lineOfBusiness` field when it is invalid JSON for Event", 4779 DocumentProvider: func() []*ord.Document { 4780 doc := fixORDDocument() 4781 doc.EventResources[0].LineOfBusiness = json.RawMessage(invalidJSON) 4782 4783 return []*ord.Document{doc} 4784 }, 4785 }, { 4786 Name: "Invalid `lineOfBusiness` field when it isn't a JSON array for Event", 4787 DocumentProvider: func() []*ord.Document { 4788 doc := fixORDDocument() 4789 doc.EventResources[0].LineOfBusiness = json.RawMessage("{}") 4790 4791 return []*ord.Document{doc} 4792 }, 4793 }, { 4794 Name: "Valid `lineOfBusiness` field when the JSON array is empty for Event", 4795 DocumentProvider: func() []*ord.Document { 4796 doc := fixORDDocument() 4797 doc.EventResources[0].LineOfBusiness = json.RawMessage("[]") 4798 4799 return []*ord.Document{doc} 4800 }, 4801 ExpectedToBeValid: true, 4802 }, { 4803 Name: "Invalid `lineOfBusiness` field when it contains non string value for Event", 4804 DocumentProvider: func() []*ord.Document { 4805 doc := fixORDDocument() 4806 doc.EventResources[0].LineOfBusiness = json.RawMessage(invalidCountriesNonStringElement) 4807 4808 return []*ord.Document{doc} 4809 }, 4810 }, { 4811 Name: "Invalid `lineOfBusiness` field when `policyLevel` is `sap` for Event", 4812 DocumentProvider: func() []*ord.Document { 4813 doc := fixORDDocument() 4814 doc.EventResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 4815 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 4816 4817 return []*ord.Document{doc} 4818 }, 4819 }, { 4820 Name: "Valid `lineOfBusiness` field when `policyLevel` is `sap partner` for Event", 4821 ExpectedToBeValid: true, 4822 DocumentProvider: func() []*ord.Document { 4823 doc := fixORDDocument() 4824 doc.EventResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 4825 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 4826 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 4827 4828 return []*ord.Document{doc} 4829 }, 4830 }, { 4831 Name: "Valid `lineOfBusiness` field when `policyLevel` is `custom`", 4832 ExpectedToBeValid: true, 4833 DocumentProvider: func() []*ord.Document { 4834 doc := fixORDDocument() 4835 doc.EventResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 4836 doc.Packages[0].PolicyLevel = ord.PolicyLevelCustom 4837 4838 return []*ord.Document{doc} 4839 }, 4840 }, { 4841 Name: "Valid `lineOfBusiness` field when `policyLevel` is `none`", 4842 ExpectedToBeValid: true, 4843 DocumentProvider: func() []*ord.Document { 4844 doc := fixORDDocument() 4845 doc.EventResources[0].LineOfBusiness = json.RawMessage(`["LoB"]`) 4846 doc.Packages[0].PolicyLevel = ord.PolicyLevelNone 4847 4848 return []*ord.Document{doc} 4849 }, 4850 }, { 4851 Name: "Invalid value for `industry` field for Event", 4852 DocumentProvider: func() []*ord.Document { 4853 doc := fixORDDocument() 4854 doc.EventResources[0].Industry = json.RawMessage(invalidIndustryElement) 4855 4856 return []*ord.Document{doc} 4857 }, 4858 }, { 4859 Name: "Invalid `industry` field when it is invalid JSON for Event", 4860 DocumentProvider: func() []*ord.Document { 4861 doc := fixORDDocument() 4862 doc.EventResources[0].Industry = json.RawMessage(invalidJSON) 4863 4864 return []*ord.Document{doc} 4865 }, 4866 }, { 4867 Name: "Invalid `industry` field when it isn't a JSON array for Event", 4868 DocumentProvider: func() []*ord.Document { 4869 doc := fixORDDocument() 4870 doc.EventResources[0].Industry = json.RawMessage("{}") 4871 4872 return []*ord.Document{doc} 4873 }, 4874 }, { 4875 Name: "Valid `industry` field when the JSON array is empty for Event", 4876 DocumentProvider: func() []*ord.Document { 4877 doc := fixORDDocument() 4878 doc.EventResources[0].Industry = json.RawMessage("[]") 4879 4880 return []*ord.Document{doc} 4881 }, 4882 ExpectedToBeValid: true, 4883 }, { 4884 Name: "Invalid `industry` field when it contains non string value for Event", 4885 DocumentProvider: func() []*ord.Document { 4886 doc := fixORDDocument() 4887 doc.EventResources[0].Industry = json.RawMessage(invalidIndustryNonStringElement) 4888 4889 return []*ord.Document{doc} 4890 }, 4891 }, { 4892 Name: "Invalid `industry` field when `policyLevel` is `sap` for Event", 4893 DocumentProvider: func() []*ord.Document { 4894 doc := fixORDDocument() 4895 doc.EventResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 4896 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 4897 4898 return []*ord.Document{doc} 4899 }, 4900 }, { 4901 Name: "Valid `industry` field when `policyLevel` is `sap partner` for Event", 4902 ExpectedToBeValid: true, 4903 DocumentProvider: func() []*ord.Document { 4904 doc := fixORDDocument() 4905 doc.EventResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 4906 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 4907 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 4908 4909 return []*ord.Document{doc} 4910 }, 4911 }, { 4912 Name: "Valid `industry` field when `policyLevel` is `custom`", 4913 ExpectedToBeValid: true, 4914 DocumentProvider: func() []*ord.Document { 4915 doc := fixORDDocument() 4916 doc.EventResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 4917 doc.Packages[0].PolicyLevel = ord.PolicyLevelCustom 4918 4919 return []*ord.Document{doc} 4920 }, 4921 }, { 4922 Name: "Valid `industry` field when `policyLevel` is `none`", 4923 ExpectedToBeValid: true, 4924 DocumentProvider: func() []*ord.Document { 4925 doc := fixORDDocument() 4926 doc.EventResources[0].Industry = json.RawMessage(`["SomeIndustry"]`) 4927 doc.Packages[0].PolicyLevel = ord.PolicyLevelNone 4928 4929 return []*ord.Document{doc} 4930 }, 4931 }, { 4932 Name: "Missing `releaseStatus` field for Event", 4933 DocumentProvider: func() []*ord.Document { 4934 doc := fixORDDocument() 4935 doc.EventResources[0].ReleaseStatus = str.Ptr("") 4936 4937 return []*ord.Document{doc} 4938 }, 4939 }, { 4940 Name: "Invalid `releaseStatus` field for Event", 4941 DocumentProvider: func() []*ord.Document { 4942 doc := fixORDDocument() 4943 doc.EventResources[0].ReleaseStatus = str.Ptr("wrongValue") 4944 4945 return []*ord.Document{doc} 4946 }, 4947 }, { 4948 Name: "Missing `sunsetDate` field when `releaseStatus` field has value `deprecated` for Event", 4949 DocumentProvider: func() []*ord.Document { 4950 doc := fixORDDocument() 4951 doc.EventResources[0].ReleaseStatus = str.Ptr("deprecated") 4952 doc.EventResources[0].Successors = json.RawMessage(fmt.Sprintf(`["%s"]`, event2ORDID)) 4953 4954 return []*ord.Document{doc} 4955 }, 4956 }, { 4957 Name: "Invalid `sunsetDate` field for Event", 4958 DocumentProvider: func() []*ord.Document { 4959 doc := fixORDDocument() 4960 doc.EventResources[0].ReleaseStatus = str.Ptr("deprecated") 4961 doc.EventResources[0].SunsetDate = str.Ptr("0000-00-00T09:35:30+0000") 4962 doc.EventResources[0].Successors = json.RawMessage(fmt.Sprintf(`["%s"]`, event2ORDID)) 4963 4964 return []*ord.Document{doc} 4965 }, 4966 }, { 4967 Name: "Missing `successors` field when `releaseStatus` field has value `deprecated` for Event", 4968 DocumentProvider: func() []*ord.Document { 4969 doc := fixORDDocument() 4970 doc.EventResources[0].ReleaseStatus = str.Ptr("deprecated") 4971 4972 return []*ord.Document{doc} 4973 }, 4974 }, { 4975 Name: "Missing `ordId` field in `PartOfConsumptionBundles` field for Event", 4976 DocumentProvider: func() []*ord.Document { 4977 doc := fixORDDocument() 4978 doc.EventResources[0].PartOfConsumptionBundles[0].BundleOrdID = "" 4979 4980 return []*ord.Document{doc} 4981 }, 4982 }, { 4983 Name: "Invalid `ordId` field in `PartOfConsumptionBundles` field for Event", 4984 DocumentProvider: func() []*ord.Document { 4985 doc := fixORDDocument() 4986 doc.EventResources[0].PartOfConsumptionBundles[0].BundleOrdID = invalidBundleOrdID 4987 4988 return []*ord.Document{doc} 4989 }, 4990 }, { 4991 Name: "Duplicate `ordId` field in `PartOfConsumptionBundles` field for Event", 4992 DocumentProvider: func() []*ord.Document { 4993 doc := fixORDDocument() 4994 doc.EventResources[0].PartOfConsumptionBundles = append(doc.EventResources[0].PartOfConsumptionBundles, &model.ConsumptionBundleReference{BundleOrdID: bundleORDID}) 4995 4996 return []*ord.Document{doc} 4997 }, 4998 }, { 4999 Name: "Present `defaultEntryPoint` field in `PartOfConsumptionBundles` field for Event", 5000 DocumentProvider: func() []*ord.Document { 5001 doc := fixORDDocument() 5002 doc.EventResources[0].PartOfConsumptionBundles[0].DefaultTargetURL = "https://exmaple.com/test/v3" 5003 5004 return []*ord.Document{doc} 5005 }, 5006 }, { 5007 Name: "Empty `PartOfConsumptionBundle` field for Event", 5008 DocumentProvider: func() []*ord.Document { 5009 doc := fixORDDocument() 5010 doc.EventResources[0].PartOfConsumptionBundles = []*model.ConsumptionBundleReference{} 5011 5012 return []*ord.Document{doc} 5013 }, 5014 }, 5015 { 5016 Name: "Invalid when `defaultConsumptionBundle` field doesn't match the required regex for Event", 5017 DocumentProvider: func() []*ord.Document { 5018 doc := fixORDDocument() 5019 doc.EventResources[0].DefaultConsumptionBundle = str.Ptr(invalidBundleOrdID) 5020 return []*ord.Document{doc} 5021 }, 5022 }, { 5023 Name: "Invalid when `defaultConsumptionBundle` field is not part of any bundles in the `partOfConsumptionBundles` field for Event", 5024 DocumentProvider: func() []*ord.Document { 5025 doc := fixORDDocument() 5026 doc.EventResources[0].DefaultConsumptionBundle = str.Ptr(secondBundleORDID) 5027 return []*ord.Document{doc} 5028 }, 5029 }, 5030 { 5031 Name: "Missing `Extensible` field when `policyLevel` is sap", 5032 DocumentProvider: func() []*ord.Document { 5033 doc := fixORDDocument() 5034 doc.EventResources[0].Extensible = nil 5035 doc.Packages[0].PolicyLevel = ord.PolicyLevelSap 5036 5037 return []*ord.Document{doc} 5038 }, 5039 }, 5040 { 5041 Name: "Missing `Extensible` field when `policyLevel` is sap partner", 5042 DocumentProvider: func() []*ord.Document { 5043 doc := fixORDDocument() 5044 doc.EventResources[0].Extensible = nil 5045 doc.Packages[0].PolicyLevel = ord.PolicyLevelSapPartner 5046 doc.Packages[0].Vendor = str.Ptr(ord.PartnerVendor) 5047 5048 return []*ord.Document{doc} 5049 }, 5050 }, 5051 { 5052 Name: "Invalid `Extensible` field due to empty json object", 5053 DocumentProvider: func() []*ord.Document { 5054 doc := fixORDDocument() 5055 doc.EventResources[0].Extensible = json.RawMessage(`{}`) 5056 5057 return []*ord.Document{doc} 5058 }, 5059 }, 5060 { 5061 Name: "Invalid `Extensible` field due to invalid json", 5062 DocumentProvider: func() []*ord.Document { 5063 doc := fixORDDocument() 5064 doc.EventResources[0].Extensible = json.RawMessage(invalidExtensibleDueToInvalidJSON) 5065 5066 return []*ord.Document{doc} 5067 }, 5068 }, 5069 { 5070 Name: "Missing `supported` field in the `extensible` object for Event", 5071 DocumentProvider: func() []*ord.Document { 5072 doc := fixORDDocument() 5073 doc.EventResources[0].Extensible = json.RawMessage(invalidExtensibleDueToNoSupportedProperty) 5074 5075 return []*ord.Document{doc} 5076 }, 5077 }, 5078 { 5079 Name: "Invalid `supported` field type in the `extensible` object for Event", 5080 DocumentProvider: func() []*ord.Document { 5081 doc := fixORDDocument() 5082 doc.EventResources[0].Extensible = json.RawMessage(invalidExtensibleDueToInvalidSupportedType) 5083 5084 return []*ord.Document{doc} 5085 }, 5086 }, 5087 { 5088 Name: "Invalid `supported` field value in the `extensible` object for Event", 5089 DocumentProvider: func() []*ord.Document { 5090 doc := fixORDDocument() 5091 doc.EventResources[0].Extensible = json.RawMessage(invalidExtensibleDueToInvalidSupportedValue) 5092 5093 return []*ord.Document{doc} 5094 }, 5095 }, 5096 { 5097 Name: "Missing `description` field when `supported` has an `automatic` value for Event", 5098 DocumentProvider: func() []*ord.Document { 5099 doc := fixORDDocument() 5100 doc.EventResources[0].Extensible = json.RawMessage(invalidExtensibleDueToSupportedAutomaticAndNoDescriptionProperty) 5101 5102 return []*ord.Document{doc} 5103 }, 5104 }, 5105 { 5106 Name: "Missing `description` field when `supported` has a `manual` value for Event", 5107 DocumentProvider: func() []*ord.Document { 5108 doc := fixORDDocument() 5109 doc.EventResources[0].Extensible = json.RawMessage(invalidExtensibleDueToSupportedManualAndNoDescriptionProperty) 5110 5111 return []*ord.Document{doc} 5112 }, 5113 }, 5114 { 5115 Name: "Empty `description` field when `supported` has a `manual` value for Event", 5116 DocumentProvider: func() []*ord.Document { 5117 doc := fixORDDocument() 5118 doc.EventResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "manual", "")) 5119 5120 return []*ord.Document{doc} 5121 }, 5122 }, 5123 { 5124 Name: "Empty `description` field when `supported` has a `automatic` value for Event", 5125 DocumentProvider: func() []*ord.Document { 5126 doc := fixORDDocument() 5127 doc.EventResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "automatic", "")) 5128 5129 return []*ord.Document{doc} 5130 }, 5131 }, 5132 { 5133 Name: "Invalid `description` field with exceeding length when `supported` has a `manual` value for Event", 5134 DocumentProvider: func() []*ord.Document { 5135 doc := fixORDDocument() 5136 doc.EventResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "manual", invalidDescriptionFieldWithExceedingMaxLength)) 5137 5138 return []*ord.Document{doc} 5139 }, 5140 }, 5141 { 5142 Name: "Invalid `description` field with exceeding length when `supported` has a `automatic` value for Event", 5143 DocumentProvider: func() []*ord.Document { 5144 doc := fixORDDocument() 5145 doc.EventResources[0].Extensible = json.RawMessage(fmt.Sprintf(invalidExtensibleDueToCorrectSupportedButInvalidDescriptionLength, "automatic", invalidDescriptionFieldWithExceedingMaxLength)) 5146 5147 return []*ord.Document{doc} 5148 }, 5149 }, 5150 5151 // Test invalid entity relations 5152 5153 { 5154 Name: "Event has a reference to unknown Package", 5155 DocumentProvider: func() []*ord.Document { 5156 doc := fixORDDocument() 5157 doc.EventResources[0].OrdPackageID = str.Ptr(unknownPackageOrdID) 5158 5159 return []*ord.Document{doc} 5160 }, 5161 }, { 5162 Name: "Event has a reference to unknown Bundle", 5163 DocumentProvider: func() []*ord.Document { 5164 doc := fixORDDocument() 5165 doc.ConsumptionBundles = fixBundleCreateInput() 5166 doc.EventResources[0].PartOfConsumptionBundles = fixEventPartOfConsumptionBundles() 5167 doc.EventResources[0].PartOfConsumptionBundles[0].BundleOrdID = unknownBundleOrdID 5168 5169 return []*ord.Document{doc} 5170 }, 5171 }, { 5172 Name: "Event has a reference to unknown Product", 5173 DocumentProvider: func() []*ord.Document { 5174 doc := fixORDDocument() 5175 doc.EventResources[0].PartOfProducts = json.RawMessage(fmt.Sprintf(`["%s"]`, unknownProductOrdID)) 5176 5177 return []*ord.Document{doc} 5178 }, 5179 }, 5180 } 5181 5182 for _, test := range tests { 5183 t.Run(test.Name, func(t *testing.T) { 5184 docs := ord.Documents{test.DocumentProvider()[0]} 5185 resourcesFromDB := ord.ResourcesFromDB{ 5186 APIs: apisFromDB, 5187 Events: eventsFromDB, 5188 Packages: pkgsFromDB, 5189 Bundles: bndlsFromDB, 5190 } 5191 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 5192 5193 if test.AfterTest != nil { 5194 test.AfterTest() 5195 } 5196 5197 if test.ExpectedToBeValid { 5198 require.NoError(t, err) 5199 } else { 5200 require.Error(t, err) 5201 } 5202 }) 5203 } 5204 } 5205 5206 func TestDocuments_ValidateProduct(t *testing.T) { 5207 var tests = []struct { 5208 Name string 5209 DocumentProvider func() []*ord.Document 5210 ExpectedToBeValid bool 5211 }{ 5212 { 5213 Name: "Valid `id` field for Product", 5214 ExpectedToBeValid: true, 5215 DocumentProvider: func() []*ord.Document { 5216 doc := fixORDDocument() 5217 doc.Products = append(doc.Products, &model.ProductInput{ 5218 OrdID: "sap:product:test:", 5219 Title: "title", 5220 ShortDescription: "Description", 5221 Vendor: ord.SapVendor, 5222 Parent: nil, 5223 CorrelationIDs: nil, 5224 Labels: nil, 5225 }) 5226 5227 return []*ord.Document{doc} 5228 }, 5229 }, { 5230 Name: "Missing `id` field for Product", 5231 DocumentProvider: func() []*ord.Document { 5232 doc := fixORDDocument() 5233 doc.Products[0].OrdID = "" 5234 5235 return []*ord.Document{doc} 5236 }, 5237 }, { 5238 Name: "Invalid `id` field for Product", 5239 DocumentProvider: func() []*ord.Document { 5240 doc := fixORDDocument() 5241 doc.Products[0].OrdID = invalidOrdID 5242 5243 return []*ord.Document{doc} 5244 }, 5245 }, { 5246 Name: "Missing `title` field for Product", 5247 DocumentProvider: func() []*ord.Document { 5248 doc := fixORDDocument() 5249 doc.Products[0].Title = "" 5250 5251 return []*ord.Document{doc} 5252 }, 5253 }, { 5254 Name: "Exceeded length of `title ` field for Product", 5255 DocumentProvider: func() []*ord.Document { 5256 doc := fixORDDocument() 5257 doc.Products[0].Title = strings.Repeat("a", invalidTitleLength) 5258 5259 return []*ord.Document{doc} 5260 }, 5261 }, { 5262 Name: "Missing `shortDescription` field for Product", 5263 DocumentProvider: func() []*ord.Document { 5264 doc := fixORDDocument() 5265 doc.Products[0].ShortDescription = "" 5266 5267 return []*ord.Document{doc} 5268 }, 5269 }, { 5270 Name: "Exceeded length of `shortDescription` field for Product", 5271 DocumentProvider: func() []*ord.Document { 5272 doc := fixORDDocument() 5273 doc.Products[0].ShortDescription = strings.Repeat("a", invalidShortDescriptionLength) 5274 5275 return []*ord.Document{doc} 5276 }, 5277 }, { 5278 Name: "New lines in `shortDescription` field for Product", 5279 DocumentProvider: func() []*ord.Document { 5280 doc := fixORDDocument() 5281 doc.Products[0].ShortDescription = `newLine\n` 5282 5283 return []*ord.Document{doc} 5284 }, 5285 }, { 5286 Name: "Missing `vendor` field for Product", 5287 DocumentProvider: func() []*ord.Document { 5288 doc := fixORDDocument() 5289 doc.Products[0].Vendor = "" 5290 5291 return []*ord.Document{doc} 5292 }, 5293 }, { 5294 Name: "Invalid `vendor` field for Product", 5295 DocumentProvider: func() []*ord.Document { 5296 doc := fixORDDocument() 5297 doc.Products[0].Vendor = invalidOrdID 5298 5299 return []*ord.Document{doc} 5300 }, 5301 }, { 5302 Name: "Invalid `vendor` field when namespace in the `id` is `sap` for Product", 5303 DocumentProvider: func() []*ord.Document { 5304 doc := fixORDDocument() 5305 doc.Products[0].OrdID = "sap:product:S4HANA_OD:" 5306 doc.Products[0].Vendor = vendor2ORDID 5307 5308 return []*ord.Document{doc} 5309 }, 5310 }, { 5311 Name: "Invalid `vendor` field when namespace in the `id` is not `sap` for Product", 5312 DocumentProvider: func() []*ord.Document { 5313 doc := fixORDDocument() 5314 doc.Products[0].OrdID = "strange:product:S4HANA_OD:" 5315 doc.Products[0].Vendor = vendorORDID 5316 5317 return []*ord.Document{doc} 5318 }, 5319 }, { 5320 Name: "Invalid `parent` field for Product", 5321 DocumentProvider: func() []*ord.Document { 5322 doc := fixORDDocument() 5323 doc.Products[0].Parent = str.Ptr(invalidType) 5324 5325 return []*ord.Document{doc} 5326 }, 5327 }, { 5328 Name: "Invalid value for `correlationIds` field for API", 5329 DocumentProvider: func() []*ord.Document { 5330 doc := fixORDDocument() 5331 doc.Products[0].CorrelationIDs = json.RawMessage(invalidCorrelationIDsElement) 5332 5333 return []*ord.Document{doc} 5334 }, 5335 }, { 5336 Name: "Invalid `correlationIds` field when it is invalid JSON for API", 5337 DocumentProvider: func() []*ord.Document { 5338 doc := fixORDDocument() 5339 doc.Products[0].CorrelationIDs = json.RawMessage(invalidJSON) 5340 5341 return []*ord.Document{doc} 5342 }, 5343 }, { 5344 Name: "Invalid `correlationIds` field when it isn't a JSON array for API", 5345 DocumentProvider: func() []*ord.Document { 5346 doc := fixORDDocument() 5347 doc.Products[0].CorrelationIDs = json.RawMessage("{}") 5348 5349 return []*ord.Document{doc} 5350 }, 5351 }, { 5352 Name: "Valid `correlationIds` field when the JSON array is empty for API", 5353 DocumentProvider: func() []*ord.Document { 5354 doc := fixORDDocument() 5355 doc.Products[0].CorrelationIDs = json.RawMessage("[]") 5356 5357 return []*ord.Document{doc} 5358 }, 5359 ExpectedToBeValid: true, 5360 }, { 5361 Name: "Invalid `correlationIds` field when it contains non string value for API", 5362 DocumentProvider: func() []*ord.Document { 5363 doc := fixORDDocument() 5364 doc.Products[0].CorrelationIDs = json.RawMessage(invalidCorrelationIDsNonStringElement) 5365 5366 return []*ord.Document{doc} 5367 }, 5368 }, { 5369 Name: "Invalid JSON `Labels` field for Product", 5370 DocumentProvider: func() []*ord.Document { 5371 doc := fixORDDocument() 5372 doc.Products[0].Labels = json.RawMessage(invalidJSON) 5373 5374 return []*ord.Document{doc} 5375 }, 5376 }, { 5377 Name: "Invalid JSON object `Labels` field for Product", 5378 DocumentProvider: func() []*ord.Document { 5379 doc := fixORDDocument() 5380 doc.Products[0].Labels = json.RawMessage(`[]`) 5381 5382 return []*ord.Document{doc} 5383 }, 5384 }, { 5385 Name: "`Labels` values are not array for Product", 5386 DocumentProvider: func() []*ord.Document { 5387 doc := fixORDDocument() 5388 doc.Products[0].Labels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 5389 5390 return []*ord.Document{doc} 5391 }, 5392 }, { 5393 Name: "`Labels` values are not array of strings for Product", 5394 DocumentProvider: func() []*ord.Document { 5395 doc := fixORDDocument() 5396 doc.Products[0].Labels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 5397 5398 return []*ord.Document{doc} 5399 }, 5400 }, { 5401 Name: "Invalid key for JSON `Labels` field for Product", 5402 DocumentProvider: func() []*ord.Document { 5403 doc := fixORDDocument() 5404 doc.Products[0].Labels = json.RawMessage(invalidLabelsWhenKeyIsWrong) 5405 5406 return []*ord.Document{doc} 5407 }, 5408 }, { 5409 Name: "Invalid JSON `DocumentationLabels` field for Product", 5410 DocumentProvider: func() []*ord.Document { 5411 doc := fixORDDocument() 5412 doc.Products[0].DocumentationLabels = json.RawMessage(invalidJSON) 5413 5414 return []*ord.Document{doc} 5415 }, 5416 }, { 5417 Name: "Invalid JSON object `DocumentationLabels` field for Product", 5418 DocumentProvider: func() []*ord.Document { 5419 doc := fixORDDocument() 5420 doc.Products[0].DocumentationLabels = json.RawMessage(`[]`) 5421 5422 return []*ord.Document{doc} 5423 }, 5424 }, { 5425 Name: "`DocumentationLabels` values are not array for Product", 5426 DocumentProvider: func() []*ord.Document { 5427 doc := fixORDDocument() 5428 doc.Products[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 5429 5430 return []*ord.Document{doc} 5431 }, 5432 }, { 5433 Name: "`DocumentationLabels` values are not array of strings for Product", 5434 DocumentProvider: func() []*ord.Document { 5435 doc := fixORDDocument() 5436 doc.Products[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 5437 5438 return []*ord.Document{doc} 5439 }, 5440 }, 5441 5442 // Test invalid entity relations 5443 5444 { 5445 Name: "Product has a reference to unknown Vendor", 5446 DocumentProvider: func() []*ord.Document { 5447 doc := fixORDDocument() 5448 doc.Products[0].Vendor = unknownVendorOrdID 5449 5450 return []*ord.Document{doc} 5451 }, 5452 }, 5453 } 5454 5455 for _, test := range tests { 5456 t.Run(test.Name, func(t *testing.T) { 5457 docs := ord.Documents{test.DocumentProvider()[0]} 5458 resourcesFromDB := ord.ResourcesFromDB{ 5459 APIs: apisFromDB, 5460 Events: eventsFromDB, 5461 Packages: pkgsFromDB, 5462 Bundles: bndlsFromDB, 5463 } 5464 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 5465 if test.ExpectedToBeValid { 5466 require.NoError(t, err) 5467 } else { 5468 require.Error(t, err) 5469 } 5470 }) 5471 } 5472 } 5473 5474 func TestDocuments_ValidateVendor(t *testing.T) { 5475 var tests = []struct { 5476 Name string 5477 DocumentProvider func() []*ord.Document 5478 ExpectedToBeValid bool 5479 }{ 5480 { 5481 Name: "Missing `id` field for Vendor", 5482 DocumentProvider: func() []*ord.Document { 5483 doc := fixORDDocument() 5484 doc.Vendors[0].OrdID = "" 5485 5486 return []*ord.Document{doc} 5487 }, 5488 }, { 5489 Name: "Invalid `id` field for Vendor", 5490 DocumentProvider: func() []*ord.Document { 5491 doc := fixORDDocument() 5492 doc.Vendors[0].OrdID = invalidOrdID 5493 5494 return []*ord.Document{doc} 5495 }, 5496 }, { 5497 Name: "Missing `title` field for Vendor", 5498 DocumentProvider: func() []*ord.Document { 5499 doc := fixORDDocument() 5500 doc.Vendors[0].Title = "" 5501 5502 return []*ord.Document{doc} 5503 }, 5504 }, { 5505 Name: "Exceeded length of `title ` field for Vendor", 5506 DocumentProvider: func() []*ord.Document { 5507 doc := fixORDDocument() 5508 doc.Vendors[0].Title = strings.Repeat("a", invalidTitleLength) 5509 5510 return []*ord.Document{doc} 5511 }, 5512 }, { 5513 Name: "Invalid JSON `Labels` field for Vendor", 5514 DocumentProvider: func() []*ord.Document { 5515 doc := fixORDDocument() 5516 doc.Vendors[0].Labels = json.RawMessage(invalidJSON) 5517 5518 return []*ord.Document{doc} 5519 }, 5520 }, { 5521 Name: "Invalid JSON object `Labels` field for Vendor", 5522 DocumentProvider: func() []*ord.Document { 5523 doc := fixORDDocument() 5524 doc.Vendors[0].Labels = json.RawMessage(`[]`) 5525 5526 return []*ord.Document{doc} 5527 }, 5528 }, { 5529 Name: "`Labels` values are not array for Vendor", 5530 DocumentProvider: func() []*ord.Document { 5531 doc := fixORDDocument() 5532 doc.Vendors[0].Labels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 5533 5534 return []*ord.Document{doc} 5535 }, 5536 }, { 5537 Name: "`Labels` values are not array of strings for Vendor", 5538 DocumentProvider: func() []*ord.Document { 5539 doc := fixORDDocument() 5540 doc.Vendors[0].Labels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 5541 5542 return []*ord.Document{doc} 5543 }, 5544 }, { 5545 Name: "Invalid key for JSON `Labels` field for Vendor", 5546 DocumentProvider: func() []*ord.Document { 5547 doc := fixORDDocument() 5548 doc.Vendors[0].Labels = json.RawMessage(invalidLabelsWhenKeyIsWrong) 5549 5550 return []*ord.Document{doc} 5551 }, 5552 }, { 5553 Name: "Invalid JSON `DocumentationLabels` field for Vendor", 5554 DocumentProvider: func() []*ord.Document { 5555 doc := fixORDDocument() 5556 doc.Vendors[0].DocumentationLabels = json.RawMessage(invalidJSON) 5557 5558 return []*ord.Document{doc} 5559 }, 5560 }, { 5561 Name: "Invalid JSON object `DocumentationLabels` field for Vendor", 5562 DocumentProvider: func() []*ord.Document { 5563 doc := fixORDDocument() 5564 doc.Vendors[0].DocumentationLabels = json.RawMessage(`[]`) 5565 5566 return []*ord.Document{doc} 5567 }, 5568 }, { 5569 Name: "`DocumentationLabels` values are not array for Vendor", 5570 DocumentProvider: func() []*ord.Document { 5571 doc := fixORDDocument() 5572 doc.Vendors[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValueIsNotArray) 5573 5574 return []*ord.Document{doc} 5575 }, 5576 }, { 5577 Name: "`DocumentationLabels` values are not array of strings for Vendor", 5578 DocumentProvider: func() []*ord.Document { 5579 doc := fixORDDocument() 5580 doc.Vendors[0].DocumentationLabels = json.RawMessage(invalidLabelsWhenValuesAreNotArrayOfStrings) 5581 5582 return []*ord.Document{doc} 5583 }, 5584 }, { 5585 Name: "Invalid JSON object `Partners` field for Vendor", 5586 DocumentProvider: func() []*ord.Document { 5587 doc := fixORDDocument() 5588 doc.Vendors[0].Partners = json.RawMessage(invalidJSON) 5589 5590 return []*ord.Document{doc} 5591 }, 5592 }, { 5593 Name: "`Partners` values are not array for Vendor", 5594 DocumentProvider: func() []*ord.Document { 5595 doc := fixORDDocument() 5596 doc.Vendors[0].Partners = json.RawMessage(invalidPartnersWhenValueIsNotArray) 5597 5598 return []*ord.Document{doc} 5599 }, 5600 }, { 5601 Name: "`Partners` values are not array of strings for Vendor", 5602 DocumentProvider: func() []*ord.Document { 5603 doc := fixORDDocument() 5604 doc.Vendors[0].Partners = json.RawMessage(invalidPartnersWhenValuesAreNotArrayOfStrings) 5605 5606 return []*ord.Document{doc} 5607 }, 5608 }, { 5609 Name: "`Partners` values do not match the regex rule", 5610 DocumentProvider: func() []*ord.Document { 5611 doc := fixORDDocument() 5612 doc.Vendors[0].Partners = json.RawMessage(invalidPartnersWhenValuesDoNotSatisfyRegex) 5613 5614 return []*ord.Document{doc} 5615 }, 5616 }, { 5617 Name: "Valid `Partners` field when the JSON array is empty", 5618 DocumentProvider: func() []*ord.Document { 5619 doc := fixORDDocument() 5620 doc.Vendors[0].Partners = json.RawMessage(`[]`) 5621 5622 return []*ord.Document{doc} 5623 }, 5624 ExpectedToBeValid: true, 5625 }, 5626 } 5627 5628 for _, test := range tests { 5629 t.Run(test.Name, func(t *testing.T) { 5630 docs := ord.Documents{test.DocumentProvider()[0]} 5631 resourcesFromDB := ord.ResourcesFromDB{ 5632 APIs: apisFromDB, 5633 Events: eventsFromDB, 5634 Packages: pkgsFromDB, 5635 Bundles: bndlsFromDB, 5636 } 5637 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 5638 if test.ExpectedToBeValid { 5639 require.NoError(t, err) 5640 } else { 5641 require.Error(t, err) 5642 } 5643 }) 5644 } 5645 } 5646 5647 func TestDocuments_ValidateTombstone(t *testing.T) { 5648 var tests = []struct { 5649 Name string 5650 DocumentProvider func() []*ord.Document 5651 ExpectedToBeValid bool 5652 }{ 5653 { 5654 Name: "Missing `ordId` field for Tombstone", 5655 DocumentProvider: func() []*ord.Document { 5656 doc := fixORDDocument() 5657 doc.Tombstones[0].OrdID = "" 5658 5659 return []*ord.Document{doc} 5660 }, 5661 }, { 5662 Name: "Invalid `ordId` field for Tombstone", 5663 DocumentProvider: func() []*ord.Document { 5664 doc := fixORDDocument() 5665 doc.Tombstones[0].OrdID = invalidOrdID 5666 5667 return []*ord.Document{doc} 5668 }, 5669 }, { 5670 Name: "Missing `removalDate` field for Tombstone", 5671 DocumentProvider: func() []*ord.Document { 5672 doc := fixORDDocument() 5673 doc.Tombstones[0].RemovalDate = "" 5674 5675 return []*ord.Document{doc} 5676 }, 5677 }, { 5678 Name: "Invalid `removalDate` field for Tombstone", 5679 DocumentProvider: func() []*ord.Document { 5680 doc := fixORDDocument() 5681 doc.Tombstones[0].RemovalDate = "0000-00-00T15:04:05Z" 5682 5683 return []*ord.Document{doc} 5684 }, 5685 }, 5686 } 5687 5688 for _, test := range tests { 5689 t.Run(test.Name, func(t *testing.T) { 5690 docs := ord.Documents{test.DocumentProvider()[0]} 5691 resourcesFromDB := ord.ResourcesFromDB{ 5692 APIs: apisFromDB, 5693 Events: eventsFromDB, 5694 Packages: pkgsFromDB, 5695 Bundles: bndlsFromDB, 5696 } 5697 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, nil, credentialExchangeStrategyTenantMappings) 5698 if test.ExpectedToBeValid { 5699 require.NoError(t, err) 5700 } else { 5701 require.Error(t, err) 5702 } 5703 }) 5704 } 5705 } 5706 5707 func TestDocuments_ValidateMultipleErrors(t *testing.T) { 5708 var tests = []struct { 5709 Name string 5710 DocumentProvider func() []*ord.Document 5711 ExpectedStringsInError []string 5712 }{ 5713 { 5714 Name: "Invalid value for `correlationIds` field for SystemInstance and invalid `baseUrl` for SystemInstance in one document", 5715 DocumentProvider: func() []*ord.Document { 5716 doc := fixORDDocument() 5717 doc.DescribedSystemInstance.CorrelationIDs = json.RawMessage(invalidCorrelationIDsElement) 5718 doc.DescribedSystemInstance.BaseURL = str.Ptr("http://test.com/test/v1") 5719 5720 return []*ord.Document{doc} 5721 }, 5722 ExpectedStringsInError: []string{"baseUrl", "correlationIds"}, 5723 }, 5724 { 5725 Name: "Invalid value for `correlationIds` field for SystemInstance in first doc and invalid `baseUrl` for SystemInstance in second doc", 5726 DocumentProvider: func() []*ord.Document { 5727 doc1 := fixORDDocument() 5728 doc1.DescribedSystemInstance.CorrelationIDs = json.RawMessage(invalidCorrelationIDsElement) 5729 doc2 := fixORDDocument() 5730 doc2.DescribedSystemInstance.BaseURL = str.Ptr("http://test.com/test/v1") 5731 5732 return []*ord.Document{doc1, doc2} 5733 }, 5734 ExpectedStringsInError: []string{"baseUrl", "correlationIds"}, 5735 }, 5736 } 5737 5738 for _, test := range tests { 5739 t.Run(test.Name, func(t *testing.T) { 5740 docs := ord.Documents(test.DocumentProvider()) 5741 resourcesFromDB := ord.ResourcesFromDB{ 5742 APIs: apisFromDB, 5743 Events: eventsFromDB, 5744 Packages: pkgsFromDB, 5745 Bundles: bndlsFromDB, 5746 } 5747 err := docs.Validate(baseURL, resourcesFromDB, resourceHashes, map[string]bool{}, credentialExchangeStrategyTenantMappings) 5748 if len(test.ExpectedStringsInError) != 0 { 5749 require.Error(t, err) 5750 for _, expectedStr := range test.ExpectedStringsInError { 5751 require.Contains(t, err.Error(), expectedStr) 5752 } 5753 } else { 5754 require.NoError(t, err) 5755 } 5756 }) 5757 } 5758 }