aboutsummaryrefslogtreecommitdiff
path: root/tests/rep-create.testscript
blob: c9364ed8763e65985522b1488301fc57d0204875 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# file      : tests/rep-create.testscript
# license   : MIT; see accompanying LICENSE file

.include common.testscript auth.testscript

# Source repository:
#
# rep-create
# |-- stable
# |   |-- foo-1.tar.gz
# |   `-- repositories.manifest
# `-- testing          -> stable (complement)
#     |-- foo-2.tar.gz (manifest with unknown name)
#     `-- repositories.manifest

: unsigned
:
{
  # Make sure the cloned repository has a valid location, so we can use
  # rep-info command to validate the repository info.
  #
  clone_rep = [cmdline] mkdir 1/ && cp -r $src/stable 1/

  : without-key
  :
  {
    $clone_rep;

    $* 1/stable/ 2>>/~%EOE% &1/stable/packages.manifest;
      added bar 1
      added foo 1
      %2 package\(s\) in .+/stable/%
      EOE

    $rep_info -p --manifest 1/stable/ >>EOO
      : 1
      name: bar
      version: 1
      summary: The "Bar" utility
      license: MIT
      url: http://www.example.org/bar
      email: bar-users@example.org
      depends: foo == 1
      bootstrap-build:
      \
      project = bar

      \
      location: bar-1.tar.gz
      sha256sum: 56528e387d1b8e18e3ee7e8510916afdb65f881acfd49d959fae6f434c3bab3c
      :
      name: foo
      version: 1
      summary: The "Foo" utility
      license: MIT
      url: http://www.example.org/foo
      email: foo-users@example.org
      bootstrap-build:
      \
      project = foo

      \
      location: foo-1.tar.gz
      sha256sum: 1d88df336611286cdbd84f5c1d87bedc774bc833e200de675e34d9b219c66cfc
      EOO
  }

  : with-key
  :
  {
    $clone_rep;

    $* --key $key 1/stable/ 2>>/~%EOE% &1/stable/packages.manifest;
      added bar 1
      added foo 1
      warning: --key option ignored
        info: repository manifest contains no certificate
        info: run 'bpkg help rep-create' for more information
      %2 package\(s\) in .+/stable/%
      EOE

    $rep_info -p --manifest 1/stable/ >>EOO
      : 1
      name: bar
      version: 1
      summary: The "Bar" utility
      license: MIT
      url: http://www.example.org/bar
      email: bar-users@example.org
      depends: foo == 1
      bootstrap-build:
      \
      project = bar

      \
      location: bar-1.tar.gz
      sha256sum: 56528e387d1b8e18e3ee7e8510916afdb65f881acfd49d959fae6f434c3bab3c
      :
      name: foo
      version: 1
      summary: The "Foo" utility
      license: MIT
      url: http://www.example.org/foo
      email: foo-users@example.org
      bootstrap-build:
      \
      project = foo

      \
      location: foo-1.tar.gz
      sha256sum: 1d88df336611286cdbd84f5c1d87bedc774bc833e200de675e34d9b219c66cfc
      EOO
  }
}

: signed
:
: Here we sign the 'stable' repository with the certificate prior to running
: tests.
:
{
  +cp -r $src/stable ./ && cat <<<$cert_manifest >+stable/repositories.manifest

  # Make sure the cloned repository has a valid location, so we can use
  # rep-info command to validate the repository info.
  #
  clone_rep = [cmdline] mkdir 1/ && cp -r ../stable 1/

  : with-key
  :
  : Note that as we re-create the repositories.manifest file on the fly (see
  : above) its sha256sum can vary due to CRs mix-in on Windows. That explains
  : why we do not match it exactly.
  :
  {
    $clone_rep;

    $* --key $key 1/stable/ 2>>/~%EOE% &1/stable/packages.manifest \
                                       &1/stable/signature.manifest;
      added bar 1
      added foo 1
      %2 package\(s\) in .+/stable/%
      EOE

    $rep_info --cert-fingerprint -p --manifest 1/stable/ >>~"%EOO%"
      $cert_fp
      : 1
      name: bar
      version: 1
      summary: The "Bar" utility
      license: MIT
      url: http://www.example.org/bar
      email: bar-users@example.org
      depends: foo == 1
      bootstrap-build:
      \\
      project = bar

      \\
      location: bar-1.tar.gz
      sha256sum: 56528e387d1b8e18e3ee7e8510916afdb65f881acfd49d959fae6f434c3bab3c
      :
      name: foo
      version: 1
      summary: The "Foo" utility
      license: MIT
      url: http://www.example.org/foo
      email: foo-users@example.org
      bootstrap-build:
      \\
      project = foo

      \\
      location: foo-1.tar.gz
      sha256sum: 1d88df336611286cdbd84f5c1d87bedc774bc833e200de675e34d9b219c66cfc
      EOO
  }

  : remote-key-option-failure
  :
  : Test that bpkg-rep-create fails for the remote --key option.
  :
  {
    $clone_rep;

    touch .git; # Pretend we are in the git repository.

    mkdir .build2;
    echo "--key $key" >=.build2/bpkg-rep-create.options;

    $* 1/stable/ 2>>/~%EOE% != 0
      %.+/bpkg-rep-create.options: error: --key <name> in remote default options file%
      EOE
  }

  : without-key
  :
  $clone_rep;
  $* 1/stable/ 2>>EOE &1/stable/packages.manifest != 0
    added bar 1
    added foo 1
    error: --key option required
      info: repository manifest contains a certificate
      info: run 'bpkg help rep-create' for more information
    EOE
}

: unknown-name
:
: Test that package manifest that contains an unknown name is properly handled.
:
{
  clone_rep = [cmdline] cp -r $src/testing ./

  : fail
  :
  $clone_rep;
  $* testing/ 2>>/EOE != 0
    foo-2/manifest:8:1: error: unknown name 'color' in package manifest
      info: package archive testing/foo-2.tar.gz
    EOE

  : ignore
  :
  $clone_rep;
  $* --ignore-unknown testing/ 2>>/~%EOE% &testing/packages.manifest
    added foo 2
    %1 package\(s\) in .+/testing/%
    EOE
}

: broken-repo
:
: Here we break the 'stable' repository prior to running a test.
:
{
  clone_rep = [cmdline] cp -r $src/stable ./

  : no-repositories-manifest
  :
  {
    $clone_rep &!stable/repositories.manifest;
    rm stable/repositories.manifest;

    $* stable/ 2>/'error: file stable/repositories.manifest does not exist' != 0
  }

  : unexpected-file
  :
  {
    $clone_rep;
    touch stable/foo;

    $* stable/ 2>>/EOE != 0
      error: unknown compression method in stable/foo
      EOE
  }
}