You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.4 KiB

  1. // Copyright (c) 2015-2024 MinIO, Inc.
  2. //
  3. // This file is part of MinIO Object Storage stack
  4. //
  5. // This program is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. package cmd
  18. import (
  19. "net/http"
  20. "net/http/httptest"
  21. "reflect"
  22. "testing"
  23. xhttp "github.com/minio/minio/internal/http"
  24. )
  25. // TestGetAndValidateAttributesOpts is currently minimal and covers a subset of getAndValidateAttributesOpts(),
  26. // it is intended to be expanded when the function is worked on in the future.
  27. func TestGetAndValidateAttributesOpts(t *testing.T) {
  28. globalBucketVersioningSys = &BucketVersioningSys{}
  29. bucket := minioMetaBucket
  30. ctx := t.Context()
  31. testCases := []struct {
  32. name string
  33. headers http.Header
  34. wantObjectAttrs map[string]struct{}
  35. }{
  36. {
  37. name: "empty header",
  38. headers: http.Header{},
  39. wantObjectAttrs: map[string]struct{}{},
  40. },
  41. {
  42. name: "single header line",
  43. headers: http.Header{
  44. xhttp.AmzObjectAttributes: []string{"test1,test2"},
  45. },
  46. wantObjectAttrs: map[string]struct{}{
  47. "test1": {}, "test2": {},
  48. },
  49. },
  50. {
  51. name: "multiple header lines with some duplicates",
  52. headers: http.Header{
  53. xhttp.AmzObjectAttributes: []string{"test1,test2", "test3,test4", "test4,test3"},
  54. },
  55. wantObjectAttrs: map[string]struct{}{
  56. "test1": {}, "test2": {}, "test3": {}, "test4": {},
  57. },
  58. },
  59. }
  60. for _, testCase := range testCases {
  61. t.Run(testCase.name, func(t *testing.T) {
  62. rec := httptest.NewRecorder()
  63. req := httptest.NewRequest("GET", "/test", nil)
  64. req.Header = testCase.headers
  65. opts, _ := getAndValidateAttributesOpts(ctx, rec, req, bucket, "testobject")
  66. if !reflect.DeepEqual(opts.ObjectAttributes, testCase.wantObjectAttrs) {
  67. t.Errorf("want opts %v, got %v", testCase.wantObjectAttrs, opts.ObjectAttributes)
  68. }
  69. })
  70. }
  71. }