master
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24#
25import difflib
26import filecmp
27import logging
28import os
30import pytest
31from testenv import CurlClient, Env, Sshd
33log = logging.getLogger(__name__)
36@pytest.mark.skipif(condition=not Env.curl_has_protocol('scp'), reason="curl built without scp:")
37@pytest.mark.skipif(condition=not Env.has_sshd(), reason="missing sshd")
38class TestScp:
40 @pytest.fixture(autouse=True, scope='class')
41 @classmethod
42 def _class_scope(cls, env, sshd):
43 env.make_data_file(indir=sshd.home_dir, fname="data-10k", fsize=10 * 1024)
44 env.make_data_file(indir=sshd.home_dir, fname="data-10m", fsize=10 * 1024 * 1024)
45 env.make_data_file(indir=env.gen_dir, fname="data-10k", fsize=10 * 1024)
46 env.make_data_file(indir=env.gen_dir, fname="data-10m", fsize=10 * 1024 * 1024)
48 def test_50_01_insecure(self, env: Env, sshd: Sshd):
49 curl = CurlClient(env=env)
50 doc_file = os.path.join(sshd.home_dir, 'data')
51 url = f'scp://{env.domain1}:{sshd.port}/{doc_file}'
52 r = curl.ssh_download(urls=[url], extra_args=[
53 '--insecure',
54 '--pubkey', sshd.user1_pubkey_file,
55 '--key', sshd.user1_privkey_file,
56 '--user', f'{os.environ["USER"]}:',
57 ])
58 r.check_exit_code(0)
60 def test_50_02_unknown_hosts(self, env: Env, sshd: Sshd):
61 curl = CurlClient(env=env)
62 doc_file = os.path.join(sshd.home_dir, 'data')
63 url = f'scp://{env.domain1}:{sshd.port}/{doc_file}'
64 r = curl.ssh_download(urls=[url], extra_args=[
65 '--knownhosts', sshd.unknown_hosts,
66 '--pubkey', sshd.user1_pubkey_file,
67 '--key', sshd.user1_privkey_file,
68 '--user', f'{os.environ["USER"]}:',
69 ])
70 r.check_exit_code(60) # CURLE_PEER_FAILED_VERIFICATION
72 def test_50_03_known_hosts(self, env: Env, sshd: Sshd):
73 curl = CurlClient(env=env)
74 doc_file = os.path.join(sshd.home_dir, 'data')
75 url = f'scp://{env.domain1}:{sshd.port}/{doc_file}'
76 r = curl.ssh_download(urls=[url], extra_args=[
77 '--knownhosts', sshd.known_hosts,
78 '--pubkey', sshd.user1_pubkey_file,
79 '--key', sshd.user1_privkey_file,
80 '--user', f'{os.environ["USER"]}:',
81 ])
82 r.check_exit_code(0)
84 # use key not in authorized_keys file
85 def test_50_04_unauth_user(self, env: Env, sshd: Sshd):
86 curl = CurlClient(env=env)
87 doc_file = os.path.join(sshd.home_dir, 'data')
88 url = f'scp://{env.domain1}:{sshd.port}/{doc_file}'
89 r = curl.ssh_download(urls=[url], extra_args=[
90 '--knownhosts', sshd.known_hosts,
91 '--pubkey', sshd.user2_pubkey_file,
92 '--key', sshd.user2_privkey_file,
93 '--user', f'{os.environ["USER"]}:',
94 ])
95 r.check_exit_code(67) # CURLE_LOGIN_DENIED
97 def test_50_10_dl_single(self, env: Env, sshd: Sshd):
98 count = 1
99 curl = CurlClient(env=env)
100 doc_file = os.path.join(sshd.home_dir, 'data-10k')
101 url = f'scp://{env.domain1}:{sshd.port}/{doc_file}?[0-{count-1}]'
102 r = curl.ssh_download(urls=[url], extra_args=[
103 '--knownhosts', sshd.known_hosts,
104 '--pubkey', sshd.user1_pubkey_file,
105 '--key', sshd.user1_privkey_file,
106 '--user', f'{os.environ["USER"]}:',
107 ])
108 r.check_exit_code(0)
109 self.check_downloads(curl, doc_file, count)
111 def test_50_11_dl_serial(self, env: Env, sshd: Sshd):
112 count = 5
113 curl = CurlClient(env=env)
114 doc_file = os.path.join(sshd.home_dir, 'data-10k')
115 url = f'scp://{env.domain1}:{sshd.port}/{doc_file}?[0-{count-1}]'
116 r = curl.ssh_download(urls=[url], extra_args=[
117 '--knownhosts', sshd.known_hosts,
118 '--pubkey', sshd.user1_pubkey_file,
119 '--key', sshd.user1_privkey_file,
120 '--user', f'{os.environ["USER"]}:',
121 ])
122 r.check_exit_code(0)
123 self.check_downloads(curl, doc_file, count)
125 def test_50_12_dl_parallel(self, env: Env, sshd: Sshd):
126 count = 5
127 curl = CurlClient(env=env)
128 doc_file = os.path.join(sshd.home_dir, 'data-10k')
129 url = f'scp://{env.domain1}:{sshd.port}/{doc_file}?[0-{count-1}]'
130 r = curl.http_download(urls=[url], extra_args=[
131 '--parallel',
132 '--knownhosts', sshd.known_hosts,
133 '--pubkey', sshd.user1_pubkey_file,
134 '--key', sshd.user1_privkey_file,
135 '--user', f'{os.environ["USER"]}:',
136 ])
137 r.check_exit_code(0)
138 self.check_downloads(curl, doc_file, count)
140 def test_50_20_ul_single(self, env: Env, sshd: Sshd):
141 srcfile = os.path.join(env.gen_dir, 'data-10k')
142 destfile = os.path.join(sshd.home_dir, 'upload_20.data')
143 curl = CurlClient(env=env)
144 url = f'scp://{env.domain1}:{sshd.port}/{destfile}'
145 r = curl.ssh_upload(urls=[url], fupload=srcfile, extra_args=[
146 '--knownhosts', sshd.known_hosts,
147 '--pubkey', sshd.user1_pubkey_file,
148 '--key', sshd.user1_privkey_file,
149 '--user', f'{os.environ["USER"]}:',
150 ])
151 r.check_exit_code(0)
152 self.check_upload(sshd, srcfile, destfile)
154 def test_50_21_ul_serial(self, env: Env, sshd: Sshd):
155 count = 5
156 srcfile = os.path.join(env.gen_dir, 'data-10k')
157 destfile = os.path.join(sshd.home_dir, 'upload_21.data')
158 curl = CurlClient(env=env)
159 url = f'scp://{env.domain1}:{sshd.port}/{destfile}.[0-{count-1}]'
160 r = curl.ssh_upload(urls=[url], fupload=srcfile, extra_args=[
161 '--knownhosts', sshd.known_hosts,
162 '--pubkey', sshd.user1_pubkey_file,
163 '--key', sshd.user1_privkey_file,
164 '--user', f'{os.environ["USER"]}:',
165 ])
166 r.check_exit_code(0)
167 for i in range(count):
168 self.check_upload(sshd, srcfile, f'{destfile}.{i}')
170 def test_50_22_ul_parallel(self, env: Env, sshd: Sshd):
171 count = 5
172 srcfile = os.path.join(env.gen_dir, 'data-10k')
173 destfile = os.path.join(sshd.home_dir, 'upload_22.data')
174 curl = CurlClient(env=env)
175 url = f'scp://{env.domain1}:{sshd.port}/{destfile}.[0-{count-1}]'
176 r = curl.ssh_upload(urls=[url], fupload=srcfile, extra_args=[
177 '--parallel',
178 '--knownhosts', sshd.known_hosts,
179 '--pubkey', sshd.user1_pubkey_file,
180 '--key', sshd.user1_privkey_file,
181 '--user', f'{os.environ["USER"]}:',
182 ])
183 r.check_exit_code(0)
184 for i in range(count):
185 self.check_upload(sshd, srcfile, f'{destfile}.{i}')
187 def check_downloads(self, client, srcfile: str, count: int,
188 complete: bool = True):
189 for i in range(count):
190 dfile = client.download_file(i)
191 assert os.path.exists(dfile)
192 if complete and not filecmp.cmp(srcfile, dfile, shallow=False):
193 with open(srcfile) as fa, open(dfile) as fb:
194 a = fa.readlines()
195 b = fb.readlines()
196 diff = "".join(difflib.unified_diff(a=a, b=b,
197 fromfile=srcfile,
198 tofile=dfile,
199 n=1))
200 assert False, f'download {dfile} differs:\n{diff}'
202 def check_upload(self, sshd: Sshd, srcfile, destfile, binary=True):
203 assert os.path.exists(srcfile)
204 assert os.path.exists(destfile)
205 if not filecmp.cmp(srcfile, destfile, shallow=False):
206 with open(srcfile) as fa, open(destfile) as fb:
207 a = fa.readlines()
208 b = fb.readlines()
209 diff = "".join(difflib.unified_diff(a=a, b=b,
210 fromfile=srcfile,
211 tofile=destfile,
212 n=1))
213 assert not binary and len(diff) == 0, f'upload {destfile} differs:\n{diff}'
Diagnostics4 git calls · 211 ms
CallStatusSizeTime0211 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit6 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=6 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=6 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2001.8 KiB202 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=201 git.response.bytes=1874 git.response.cache=MISS git.response.duration_ms=202 git.fetch.wants=14be668d759914a2f17dfab851c67d025416a6c1 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1874 git.pkt.payload.max=1853 git.sideband.band1.bytes=1852 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2ed2f799c77be
- Request
- a1b1ff99…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format