about summary refs log tree commit diff stats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* Add tests for format_call_external_argvWilliam Wennerström2020-12-073-2/+61
|
* Rework url to filenameWilliam Wennerström2020-12-061-17/+63
|
* Move unique_filename_from_url functions to commonWilliam Wennerström2020-12-046-79/+88
|
* Fix stubs and move some tests to http_commonWilliam Wennerström2020-11-167-28/+10
|
* Add stubsWilliam Wennerström2020-11-163-2/+39
|
* Run make format on rebaseWilliam Wennerström2020-11-165-162/+111
|
* Remove unsafe Conent-Disposition inferringWilliam Wennerström2020-11-163-84/+35
|
* Infer filename from content-disposition or URLWilliam Wennerström2020-11-165-10/+244
| | | | | The Content-Disposition inferring is probably a bad idea security wise, so I am going to remove it.
* Move file encryption function to public headerWilliam Wennerström2020-11-163-40/+12
|
* Initial /sendfile OMEMO encryptionWilliam Wennerström2020-11-162-0/+12
|
* Remove non existent functionsMichael Vetter2020-11-021-8/+0
|
* functest: Make char constMichael Vetter2020-10-152-9/+9
|
* Merge branch 'master' of github.com:profanity-im/profanityMichael Vetter2020-07-101-3/+16
|\
| * Adapt unittestsMichael Vetter2020-07-091-3/+16
| |
* | OX: XEP-0373: OpenPGP for XMPP - Version 0.5.0 (2020-06-19)DebXWoody2020-07-101-0/+10
|/ | | | | | | | | | | Discovering Public Keys via PEP * 4.3 Discovering Public Keys of a User * 4.4 Requesting Public Keys * Import Public Keys into GnuPG's local keyring. Issue: #1331
* Apply coding styleMichael Vetter2020-07-0766-2522/+4364
|
* Revert "Apply coding style"Michael Vetter2020-07-0766-4502/+2660
| | | | | | This reverts commit 9b55f2dec0ea27a9ce4856e303425e12f866cea2. Sorting the includes creates some problems.
* Apply coding styleMichael Vetter2020-07-0766-2660/+4502
| | | | Regards https://github.com/profanity-im/profanity/issues/1396
* Tests: Add ox_announce_public_key stubMichael Vetter2020-07-061-0/+9
|
* Remove prefs_free_string()Michael Vetter2020-07-023-15/+15
| | | | | It just does a free. Related to b580b9ef119045f142fa4baa9689a1c5ce8864ef
* Add OX test stubsMichael Vetter2020-06-292-0/+16
|
* Add option for legacy authenticationDmitry Podgorny2020-06-057-19/+21
| | | | | | | | New options: /connect <account> [auth default|legacy] /account <account> set auth default|legacy Fixes #1236.
* Add include for waitpid to functionaltestMichael Vetter2020-06-041-0/+1
|
* Initialize ProfWin.urls_ac to NULL to fix OpenBSD buildWilliam Wennerström2020-06-031-0/+6
|
* Fix clears_chat_sessions unittestMichael Vetter2020-05-282-1/+6
|
* Add cons_show_bookmarks_ignore stubMichael Vetter2020-05-241-0/+1
|
* Fix build on sr.htMichael Vetter2020-05-221-0/+1
| | | | | | | | | | | | | | | | Hopefully fixing: ``` cc1: warnings being treated as errors tests/unittests/test_cmd_otr.c: In function 'cmd_otr_start_sends_otr_query_message_to_current_recipeint': tests/unittests/test_cmd_otr.c:422: warning: 'window.urls_ac' is used uninitialized in this function gmake[2]: *** [Makefile:1913: tests/unittests/test_cmd_otr.o] Error 1 gmake[2]: Leaving directory '/home/build/profanity' gmake[1]: *** [Makefile:2442: check-am] Error 2 gmake[1]: Leaving directory '/home/build/profanity' gmake: *** [Makefile:2445: check] Error 2 ```
* Update bookmark test stubMichael Vetter2020-05-221-2/+2
|
* Add executable stubMichael Vetter2020-05-201-1/+1
|
* Fix http_upload stubMichael Vetter2020-04-171-0/+3
|
* Update database stubMichael Vetter2020-04-071-3/+1
|
* Remove chat_log_get_previous()Michael Vetter2020-04-061-5/+0
| | | | | | | | | | | | We now dont get the log files from the text files via chat_log_get_previous() anymore. We use the sql backend via log_database_get_previous_chat(). So far it just has the same behaviour like chat_log_get_previous(), except that in _chatwin_history() we don't pass the sender to win_print_history() which should be fixed in a commit soon. And log_database_get_previous_chat() can later easily be expanded to fix https://github.com/profanity-im/profanity/issues/205.
* Add log_database_add_*() test stubsMichael Vetter2020-04-061-1/+6
|
* Fix message_send_private unittest stubMichael Vetter2020-04-061-1/+6
|
* db: add database unit test stubMichael Vetter2020-04-061-0/+31
|
* Add slashguard featureMichael Vetter2020-03-181-0/+1
| | | | | New command `/slashguard` tries to protect against typing ` /quit` by not allowing a slash in the first 4 characters.
* Add cons_avatar_setting to unit test stubMichael Vetter2020-03-101-0/+1
|
* Fix log test stubMichael Vetter2020-02-211-4/+5
|
* Fix test stubMichael Vetter2020-02-211-1/+1
| | | | Change done in eb2fbdba2efb9c81275461bf3651215b9456e496
* Allow utf8 symbols as omemo/pgp/otr indicator charMichael Vetter2020-02-201-2/+2
| | | | Fix https://github.com/profanity-im/profanity/issues/1264
* Parse mentions and triggers in muc history if display is 'regular'Michael Vetter2020-02-202-3/+3
| | | | Fix https://github.com/profanity-im/profanity/issues/1261
* Add builds.sr.ht CI for OpenBSDWilliam Wennerström2020-02-171-0/+6
| | | | | | | | * Add .builds/openbsd.yml for builds.sr.ht * Update travis-build.sh -> ci-build.sh with OpenBSD case * Fix libdl check in configure.ac (OpenBSD has libdl built-in) * Fix some minor issues found when compiling on OpenBSD with GCC (e.g. uninitialized variables)
* test: Init window.layout to make compiler happyMichael Vetter2020-02-141-0/+1
| | | | | Fix tests/unittests/test_cmd_otr.c:415: warning: 'window.layout' is used uninitialized in this function on openbsd (thanks optmzr)
* Fix testsMichael Vetter2020-02-141-1/+1
|
* xep-0308: adapt unit test stubsMichael Vetter2020-02-142-8/+6
|
* xep-0308: add cons_correction_setting stub to testsMichael Vetter2020-02-101-0/+1
|
* Fix unittest buildPaul Fariello2020-01-311-14/+14
|
* Add context to autocomplete_with_func and use it for omemo trust commandPaul Fariello2020-01-313-5/+5
| | | | Fix #1068
* Add cons_os_setting stub for testsMichael Vetter2020-01-241-0/+1
|
* Use OMEMO for offline MUC members (#1242)Paul Fariello2020-01-201-1/+1
|
21'>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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375

 
                                  
                                           



                                                   
 
                                                               
 
                           
    
                        
 
               

                                                    
 

                                      

                                                     

                    
                                          
                                                               
    
                                                     

               






                             
                    
 
                                                
                        
    
                                                     

               
                                                         



















                                         
                                                          



                                                                      
                                       










                                                 

                                                                              

                                                
                                  

























                                                                             
                                                                       



































                                               
                                          









                                                    
                                               











                                                                                     
                    








































                                                                                  
                                        




                                     
                                      







                                                                         
                    


















                                                                          
                           




















                                                                   
                  


































































































                                                                                   
#
#
#            Nim's Runtime Library
#        (c) Copyright 2014 Dominik Picheta
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module implements URI parsing as specified by RFC 3986.

import strutils, parseutils
type
  Url* = distinct string

  Uri* = object
    scheme*, username*, password*: string 
    hostname*, port*, path*, query*, anchor*: string

{.deprecated: [TUrl: Url, TUri: Uri].}

proc `$`*(url: Url): string {.deprecated.} =
  ## **Deprecated since 0.9.6**: Use ``Uri`` instead.
  return string(url)

proc `/`*(a, b: Url): Url {.deprecated.} =
  ## Joins two URLs together, separating them with / if needed.
  ##
  ## **Deprecated since 0.9.6**: Use ``Uri`` instead.
  var urlS = $a
  var bS = $b
  if urlS == "": return b
  if urlS[urlS.len-1] != '/':
    urlS.add('/')
  if bS[0] == '/':
    urlS.add(bS.substr(1))
  else:
    urlS.add(bs)
  result = Url(urlS)

proc add*(url: var Url, a: Url) {.deprecated.} =
  ## Appends url to url.
  ##
  ## **Deprecated since 0.9.6**: Use ``Uri`` instead.
  url = url / a

proc parseAuthority(authority: string, result: var Uri) =
  var i = 0
  var inPort = false
  while true:
    case authority[i]
    of '@':
      result.password = result.port
      result.port = ""
      result.username = result.hostname
      result.hostname = ""
      inPort = false
    of ':':
      inPort = true
    of '\0': break
    else:
      if inPort:
        result.port.add(authority[i])
      else:
        result.hostname.add(authority[i])
    i.inc

proc parsePath(uri: string, i: var int, result: var Uri) =
  
  i.inc parseUntil(uri, result.path, {'?', '#'}, i)

  # The 'mailto' scheme's PATH actually contains the hostname/username
  if result.scheme.toLower == "mailto":
    parseAuthority(result.path, result)
    result.path = ""

  if uri[i] == '?':
    i.inc # Skip '?'
    i.inc parseUntil(uri, result.query, {'#'}, i)

  if uri[i] == '#':
    i.inc # Skip '#'
    i.inc parseUntil(uri, result.anchor, {}, i)

proc initUri(): Uri =
  result = Uri(scheme: "", username: "", password: "", hostname: "", port: "",
                path: "", query: "", anchor: "")

proc parseUri*(uri: string): Uri =
  ## Parses a URI.
  result = initUri()

  var i = 0

  # Check if this is a reference URI (relative URI)
  if uri[i] == '/':
    parsePath(uri, i, result)
    return

  # Scheme
  i.inc parseWhile(uri, result.scheme, Letters + Digits + {'+', '-', '.'}, i)
  if uri[i] != ':':
    # Assume this is a reference URI (relative URI)
    i = 0
    result.scheme = ""
    parsePath(uri, i, result)
    return
  i.inc # Skip ':'

  # Authority
  if uri[i] == '/' and uri[i+1] == '/':
    i.inc(2) # Skip //
    var authority = ""
    i.inc parseUntil(uri, authority, {'/', '?', '#'}, i)
    if authority == "":
      raise newException(ValueError, "Expected authority got nothing.")
    parseAuthority(authority, result)

  # Path
  parsePath(uri, i, result)

proc removeDotSegments(path: string): string =
  var collection: seq[string] = @[]
  let endsWithSlash = path[path.len-1] == '/'
  var i = 0
  var currentSegment = ""
  while true:
    case path[i]
    of '/':
      collection.add(currentSegment)
      currentSegment = ""
    of '.':
      if path[i+1] == '.' and path[i+2] == '/':
        if collection.len > 0:
          discard collection.pop()
          i.inc 3
          continue
      elif path[i+1] == '/':
        i.inc 2
        continue
      currentSegment.add path[i]
    of '\0':
      if currentSegment != "":
        collection.add currentSegment
      break
    else:
      currentSegment.add path[i]
    i.inc

  result = collection.join("/")
  if endsWithSlash: result.add '/'

proc merge(base, reference: Uri): string =
  # http://tools.ietf.org/html/rfc3986#section-5.2.3
  if base.hostname != "" and base.path == "":
    '/' & reference.path
  else:
    let lastSegment = rfind(base.path, "/")
    if lastSegment == -1:
      reference.path
    else:
      base.path[0 .. lastSegment] & reference.path

proc combine*(base: Uri, reference: Uri): Uri =
  ## Combines a base URI with a reference URI.
  ##
  ## This uses the algorithm specified in
  ## `section 5.2.2 of RFC 3986 <http://tools.ietf.org/html/rfc3986#section-5.2.2>`_.
  ##
  ## This means that the slashes inside the base URI's path as well as reference
  ## URI's path affect the resulting URI.
  ##
  ## For building URIs you may wish to use \`/\` instead.
  ##
  ## Examples:
  ##
  ## .. code-block::
  ##   let foo = combine(parseUri("http://example.com/foo/bar"), parseUri("/baz"))
  ##   assert foo.path == "/baz"
  ##
  ##   let bar = combine(parseUri("http://example.com/foo/bar"), parseUri("baz"))
  ##   assert foo.path == "/foo/baz"
  ##
  ##   let bar = combine(parseUri("http://example.com/foo/bar/"), parseUri("baz"))
  ##   assert foo.path == "/foo/bar/baz"
  
  template setAuthority(dest, src: expr): stmt =
    dest.hostname = src.hostname
    dest.username = src.username
    dest.port = src.port
    dest.password = src.password

  result = initUri()
  if reference.scheme != base.scheme and reference.scheme != "":
    result = reference
    result.path = removeDotSegments(result.path)
  else:
    if reference.hostname != "":
      setAuthority(result, reference)
      result.path = removeDotSegments(reference.path)
      result.query = reference.query
    else:
      if reference.path == "":
        result.path = base.path
        if reference.query != "":
          result.query = reference.query
        else:
          result.query = base.query
      else:
        if reference.path.startsWith("/"):
          result.path = removeDotSegments(reference.path)
        else:
          result.path = removeDotSegments(merge(base, reference))
        result.query = reference.query
      setAuthority(result, base)
    result.scheme = base.scheme
  result.anchor = reference.anchor

proc combine*(uris: varargs[Uri]): Uri =
  ## Combines multiple URIs together.
  result = uris[0]
  for i in 1 .. <uris.len:
    result = combine(result, uris[i])

proc `/`*(x: Uri, path: string): Uri =
  ## Concatenates the path specified to the specified URI's path.
  ##
  ## Contrary to the ``combine`` procedure you do not have to worry about
  ## the slashes at the beginning and end of the path and URI's path
  ## respectively.
  ##
  ## Examples:
  ##
  ## .. code-block::
  ##   let foo = parseUri("http://example.com/foo/bar") / parseUri("/baz")
  ##   assert foo.path == "/foo/bar/baz"
  ##
  ##   let bar = parseUri("http://example.com/foo/bar") / parseUri("baz")
  ##   assert foo.path == "/foo/bar/baz"
  ##
  ##   let bar = parseUri("http://example.com/foo/bar/") / parseUri("baz")
  ##   assert foo.path == "/foo/bar/baz"
  result = x
  if result.path[result.path.len-1] == '/':
    if path[0] == '/':
      result.path.add(path[1 .. path.len-1])
    else:
      result.path.add(path)
  else:
    if path[0] != '/':
      result.path.add '/'
    result.path.add(path)

proc `$`*(u: Uri): string =
  ## Returns the string representation of the specified URI object.
  result = ""
  if u.scheme.len > 0:
    result.add(u.scheme)
    result.add("://")
  if u.username.len > 0:
    result.add(u.username)
    if u.password.len > 0:
      result.add(":")
      result.add(u.password)
    result.add("@")
  result.add(u.hostname)
  if u.port.len > 0:
    result.add(":")
    result.add(u.port)
  if u.path.len > 0:
    if u.path[0] != '/': result.add("/")
    result.add(u.path)
  result.add(u.query)
  result.add(u.anchor)

when isMainModule:
  block:
    let test = parseUri("http://localhost:8080/test")
    doAssert test.scheme == "http"
    doAssert test.port == "8080"
    doAssert test.path == "/test"
    doAssert test.hostname == "localhost"

  block:
    let test = parseUri("foo://username:password@example.com:8042/over/there" &
                        "/index.dtb?type=animal&name=narwhal#nose")
    doAssert test.scheme == "foo"
    doAssert test.username == "username"
    doAssert test.password == "password"
    doAssert test.hostname == "example.com"
    doAssert test.port == "8042"
    doAssert test.path == "/over/there/index.dtb"
    doAssert test.query == "type=animal&name=narwhal"
    doAssert test.anchor == "nose"

  block:
    let test = parseUri("urn:example:animal:ferret:nose")
    doAssert test.scheme == "urn"
    doAssert test.path == "example:animal:ferret:nose"

  block:
    let test = parseUri("mailto:username@example.com?subject=Topic")
    doAssert test.scheme == "mailto"
    doAssert test.username == "username"
    doAssert test.hostname == "example.com"
    doAssert test.query == "subject=Topic"

  block:
    let test = parseUri("magnet:?xt=urn:sha1:72hsga62ba515sbd62&dn=foobar")
    doAssert test.scheme == "magnet"
    doAssert test.query == "xt=urn:sha1:72hsga62ba515sbd62&dn=foobar"

  block:
    let test = parseUri("/test/foo/bar?q=2#asdf")
    doAssert test.scheme == ""
    doAssert test.path == "/test/foo/bar"
    doAssert test.query == "q=2"
    doAssert test.anchor == "asdf"

  block:
    let test = parseUri("test/no/slash")
    doAssert test.path == "test/no/slash"

  # Remove dot segments tests
  block:
    doAssert removeDotSegments("/foo/bar/baz") == "/foo/bar/baz"

  # Combine tests
  block:
    let concat = combine(parseUri("http://google.com/foo/bar/"), parseUri("baz"))
    doAssert concat.path == "/foo/bar/baz"
    doAssert concat.hostname == "google.com"
    doAssert concat.scheme == "http"

  block:
    let concat = combine(parseUri("http://google.com/foo"), parseUri("/baz"))
    doAssert concat.path == "/baz"
    doAssert concat.hostname == "google.com"
    doAssert concat.scheme == "http"

  block:
    let concat = combine(parseUri("http://google.com/foo/test"), parseUri("bar"))
    doAssert concat.path == "/foo/bar"

  block:
    let concat = combine(parseUri("http://google.com/foo/test"), parseUri("/bar"))
    doAssert concat.path == "/bar"

  block:
    let concat = combine(parseUri("http://google.com/foo/test"), parseUri("bar"))
    doAssert concat.path == "/foo/bar"

  block:
    let concat = combine(parseUri("http://google.com/foo/test/"), parseUri("bar"))
    doAssert concat.path == "/foo/test/bar"

  block:
    let concat = combine(parseUri("http://google.com/foo/test/"), parseUri("bar/"))
    doAssert concat.path == "/foo/test/bar/"

  block:
    let concat = combine(parseUri("http://google.com/foo/test/"), parseUri("bar/"),
                         parseUri("baz"))
    doAssert concat.path == "/foo/test/bar/baz"

  # `/` tests
  block:
    let test = parseUri("http://example.com/foo") / "bar/asd"
    doAssert test.path == "/foo/bar/asd"

  block:
    let test = parseUri("http://example.com/foo/") / "/bar/asd"
    doAssert test.path == "/foo/bar/asd"