├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── feature_request.md │ └── question.md └── workflows │ ├── ci.yml │ └── reuse.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.txt ├── LICENSES └── GPL-3.0-or-later.txt ├── Makefile ├── README.md ├── REUSE.toml ├── impostman.el └── tests ├── custom.org ├── custom_no_vars.org ├── httpbin.postman_collection.json ├── httpbin.postman_environment.json ├── impostman-test.el ├── restclient.org ├── restclient_no_vars.org ├── verb.org └── verb_no_vars.org /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a bug report 4 | labels: bug 5 | 6 | --- 7 | 8 | ## Bug summary 9 | 10 | 11 | 12 | ## Steps to reproduce 13 | 14 | 1.  15 | 2.  16 | 3.  17 | 18 | ## Current behavior 19 | 20 | 21 | 22 | ## Expected behavior 23 | 24 | 25 | 26 | ## Suggested solutions 27 | 28 | 29 | 30 | ## Additional information 31 | 32 | 33 | 34 | --- 35 | 36 | 37 | 38 | - Impostman version (output of `impostman-version`):  39 | - Emacs version (output of `emacs-version`):  40 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2025 Sébastien Helleu 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-or-later 4 | 5 | blank_issues_enabled: false 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Request a new feature / enhancement 4 | labels: feature 5 | 6 | --- 7 | 8 | ## Feature description 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question 4 | labels: question 5 | 6 | --- 7 | 8 | ## Question 9 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020-2025 Sébastien Helleu 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-or-later 4 | 5 | name: CI 6 | 7 | on: 8 | - push 9 | - pull_request 10 | 11 | jobs: 12 | 13 | build: 14 | 15 | strategy: 16 | matrix: 17 | os: 18 | - ubuntu-24.04 19 | - macos-14 20 | emacs-version: 21 | - "28.1" 22 | - "28.2" 23 | - "29.1" 24 | - "29.2" 25 | - "29.3" 26 | - "29.4" 27 | - "30.1" 28 | - "snapshot" 29 | 30 | name: Emacs ${{ matrix.emacs-version }} on ${{ matrix.os }} 31 | runs-on: ${{ matrix.os }} 32 | 33 | steps: 34 | 35 | - uses: purcell/setup-emacs@master 36 | with: 37 | version: ${{ matrix.emacs-version }} 38 | 39 | - uses: actions/checkout@v4 40 | 41 | - name: Compilation 42 | run: make compile 43 | 44 | - name: Tests 45 | run: make test 46 | -------------------------------------------------------------------------------- /.github/workflows/reuse.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2025 Sébastien Helleu 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-or-later 4 | 5 | name: REUSE Compliance Check 6 | 7 | on: 8 | - push 9 | - pull_request 10 | 11 | jobs: 12 | 13 | test: 14 | 15 | runs-on: ubuntu-24.04 16 | 17 | steps: 18 | 19 | - uses: actions/checkout@v4 20 | 21 | - name: REUSE Compliance Check 22 | uses: fsfe/reuse-action@v4 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021-2025 Sébastien Helleu 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-or-later 4 | 5 | *.elc 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Impostman ChangeLog 8 | 9 | ## Version 0.2.0 (2021-12-11) 10 | 11 | ### Changed 12 | 13 | - Auto-load function `impostman-version` 14 | 15 | ### Added 16 | 17 | - Read variables in collection ([#2](https://github.com/flashcode/impostman/issues/2)) 18 | - Import Postman environment with a collection, add support of variables, add option `impostman-use-variables` ([#1](https://github.com/flashcode/impostman/issues/1)) 19 | 20 | ## Version 0.1.0 (2021-01-11) 21 | 22 | ### Added 23 | 24 | - First release 25 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /LICENSES/GPL-3.0-or-later.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright © 2007 Free Software Foundation, Inc. 5 | 6 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 11 | 12 | The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. 13 | 14 | When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. 15 | 16 | To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. 17 | 18 | For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. 19 | 20 | Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. 21 | 22 | For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. 23 | 24 | Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. 25 | 26 | Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. 27 | 28 | The precise terms and conditions for copying, distribution and modification follow. 29 | 30 | TERMS AND CONDITIONS 31 | 32 | 0. Definitions. 33 | 34 | “This License” refers to version 3 of the GNU General Public License. 35 | 36 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 37 | 38 | “The Program” refers to any copyrightable work licensed under this License. Each licensee is addressed as “you”. “Licensees” and “recipients” may be individuals or organizations. 39 | 40 | To “modify” a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a “modified version” of the earlier work or a work “based on” the earlier work. 41 | 42 | A “covered work” means either the unmodified Program or a work based on the Program. 43 | 44 | To “propagate” a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. 45 | 46 | To “convey” a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. 47 | 48 | An interactive user interface displays “Appropriate Legal Notices” to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 49 | 50 | 1. Source Code. 51 | The “source code” for a work means the preferred form of the work for making modifications to it. “Object code” means any non-source form of a work. 52 | 53 | A “Standard Interface” means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. 54 | 55 | The “System Libraries” of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A “Major Component”, in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. 56 | 57 | The “Corresponding Source” for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. 58 | 59 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 60 | 61 | The Corresponding Source for a work in source code form is that same work. 62 | 63 | 2. Basic Permissions. 64 | All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. 65 | 66 | You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. 67 | 68 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 69 | 70 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 71 | No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. 72 | 73 | When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 74 | 75 | 4. Conveying Verbatim Copies. 76 | You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. 77 | 78 | You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 79 | 80 | 5. Conveying Modified Source Versions. 81 | You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: 82 | 83 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 84 | 85 | b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to “keep intact all notices”. 86 | 87 | c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. 88 | 89 | d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. 90 | 91 | A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an “aggregate” if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 92 | 93 | 6. Conveying Non-Source Forms. 94 | You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: 95 | 96 | a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. 97 | 98 | b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. 99 | 100 | c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. 101 | 102 | d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. 103 | 104 | e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. 105 | 106 | A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. 107 | 108 | A “User Product” is either (1) a “consumer product”, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, “normally used” refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. 109 | 110 | “Installation Information” for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. 111 | 112 | If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). 113 | 114 | The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. 115 | 116 | Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 117 | 118 | 7. Additional Terms. 119 | “Additional permissions” are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. 120 | 121 | When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. 122 | 123 | Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: 124 | 125 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 126 | 127 | b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or 128 | 129 | c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or 130 | 131 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 132 | 133 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 134 | 135 | f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. 136 | 137 | All other non-permissive additional terms are considered “further restrictions” within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. 138 | 139 | If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. 140 | 141 | Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 142 | 143 | 8. Termination. 144 | You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). 145 | 146 | However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. 147 | 148 | Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. 149 | 150 | Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 151 | 152 | 9. Acceptance Not Required for Having Copies. 153 | You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 154 | 155 | 10. Automatic Licensing of Downstream Recipients. 156 | Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. 157 | 158 | An “entity transaction” is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. 159 | 160 | You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 161 | 162 | 11. Patents. 163 | A “contributor” is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's “contributor version”. 164 | 165 | A contributor's “essential patent claims” are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, “control” includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. 166 | 167 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. 168 | 169 | In the following three paragraphs, a “patent license” is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To “grant” such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. 170 | 171 | If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. “Knowingly relying” means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. 172 | 173 | If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. 174 | 175 | A patent license is “discriminatory” if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. 176 | 177 | Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 178 | 179 | 12. No Surrender of Others' Freedom. 180 | If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 181 | 182 | 13. Use with the GNU Affero General Public License. 183 | Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 184 | 185 | 14. Revised Versions of this License. 186 | The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. 187 | 188 | Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License “or any later version” applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. 189 | 190 | If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. 191 | 192 | Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 193 | 194 | 15. Disclaimer of Warranty. 195 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 196 | 197 | 16. Limitation of Liability. 198 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 199 | 200 | 17. Interpretation of Sections 15 and 16. 201 | If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. 202 | 203 | END OF TERMS AND CONDITIONS 204 | 205 | How to Apply These Terms to Your New Programs 206 | 207 | If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. 208 | 209 | To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found. 210 | 211 | 212 | Copyright (C) 213 | 214 | This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 215 | 216 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 217 | 218 | You should have received a copy of the GNU General Public License along with this program. If not, see . 219 | 220 | Also add information on how to contact you by electronic and paper mail. 221 | 222 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 223 | 224 | Copyright (C) 225 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 226 | This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. 227 | 228 | The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an “about box”. 229 | 230 | You should also get your employer (if you work as a programmer) or school, if any, to sign a “copyright disclaimer” for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . 231 | 232 | The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . 233 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # SPDX-FileCopyrightText: 2020-2025 Sébastien Helleu 3 | # 4 | # SPDX-License-Identifier: GPL-3.0-or-later 5 | # 6 | # Impostman is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # Impostman is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with Impostman. If not, see . 18 | # 19 | 20 | EMACS ?= emacs 21 | RM ?= rm -f 22 | 23 | .PHONY: all compile test clean 24 | 25 | all: compile test 26 | 27 | compile: 28 | $(EMACS) -Q -batch --eval "(setq byte-compile-error-on-warn t)" -f batch-byte-compile impostman.el 29 | 30 | test: clean 31 | cd tests && $(EMACS) -Q -batch -L . -L .. -l impostman -l impostman-test -f ert-run-tests-batch-and-exit 32 | 33 | clean: 34 | $(RM) *.elc 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # Import of Postman collections in Emacs 8 | 9 | [![Build Status](https://github.com/flashcode/impostman/workflows/CI/badge.svg)](https://github.com/flashcode/impostman/actions?query=workflow%3A%22CI%22) 10 | [![MELPA](https://melpa.org/packages/impostman-badge.svg)](https://melpa.org/#/impostman) 11 | [![MELPA Stable](https://stable.melpa.org/packages/impostman-badge.svg)](https://stable.melpa.org/#/impostman) 12 | [![REUSE status](https://api.reuse.software/badge/github.com/flashcode/impostman)](https://api.reuse.software/info/github.com/flashcode/impostman) 13 | 14 | Postman collections and environments can be imported and used with these Emacs HTTP clients: 15 | 16 | - [verb](https://github.com/federicotdn/verb) 17 | - [restclient](https://github.com/pashky/restclient.el) 18 | - other clients with your own functions, see [Add new output](#add-new-output). 19 | 20 | ## Requirements 21 | 22 | This package requires: 23 | 24 | - Emacs ≥ 27.1 (it uses the native support for JSON introduced in Emacs 27). 25 | 26 | Optional dependencies: 27 | 28 | - [verb](https://github.com/federicotdn/verb) 29 | - [restclient](https://github.com/pashky/restclient.el). 30 | 31 | Note: without these optional dependencies, you can still convert to all formats, but the mode will not be set in the buffer once converted. 32 | 33 | ## Installation 34 | 35 | You can install Impostman with `package-install` command, either from [MELPA](https://melpa.org/) or [MELPA Stable](https://stable.melpa.org/): 36 | 37 | M-x `package-install` RET `impostman` RET 38 | 39 | Alternatively, you can deploy impostman.el into your site-lisp as usual, then add this line to your Emacs initialization file: 40 | 41 | ```elisp 42 | (require 'impostman) 43 | ``` 44 | 45 | ## Usage 46 | 47 | Two functions can be called interactively to import a Postman collection, with an optional environment: 48 | 49 | - M-x `impostman-import-file` RET 50 | - M-x `impostman-import-string` RET 51 | 52 | The function `impostman-import-file` takes three optional parameters (they are asked interactively if not provided): 53 | 54 | - `collection` (optional): the Postman collection 55 | - `environment` (optional): the Postman environment (must be given if variables are used in the collection, can be empty string if the collection does not use any variable from an environment) 56 | - `output` (optional): the output type: `verb`, `restclient` or your custom output. 57 | 58 | Example: 59 | 60 | ```elisp 61 | (impostman-import-file "/path/to/collection.json" "/path/to/environment.json" "verb") 62 | ``` 63 | 64 | The function `impostman-import-string` takes three parameters (the third is optional and asked interactively if not provided): 65 | 66 | - `collection`: the string with the collection (JSON format) 67 | - `environment`: the string with the environment (JSON format) (must be given if variables are used in the collection, can be empty string if the collection does not use any variable from an environment) 68 | - `output` (optional): the output type (`verb` or `restclient`). 69 | 70 | Example: 71 | 72 | ```elisp 73 | (impostman-import-string "{}" "" "verb") 74 | ``` 75 | 76 | The result is displayed in a new buffer with the Emacs HTTP client, and the mode is set to: 77 | 78 | - verb: `org-mode` (major) and `verb-mode` (minor) 79 | - restclient: `restclient-mode`. 80 | 81 | ## Customization 82 | 83 | Some options can be customized to alter the output, you can list and change them with: 84 | 85 | M-x `customize-group` RET `impostman` RET 86 | 87 | List of variables: 88 | 89 | - `impostman-auth-basic-as-elisp-code` (boolean, default: `t`): convert Basic authentication header to elisp code so that the username and password can be easily edited; if set to `nil`, the header is written in Base64 90 | - `impostman-use-variables` (boolean, default: `t`): keep Postman variables in the output and define variables according to the 91 | output; if set to `nil`, no variables are used, they are directly replaced by their values during the import of collection 92 | - `impostman-outputs-alist` (alist, default keys: `verb` and `restclient`): list of outputs, see [Add new output](#add-new-output). 93 | 94 | ## Add new output 95 | 96 | Two low-level functions can also be called (non interactively), with a custom output (alist). 97 | 98 | This alist must be defined like this, for example if your output is for walkman (another HTTP client for Emacs): 99 | 100 | ```elisp 101 | (defconst my-impostman-walkman-alist 102 | '((init . my-impostman-walkman-init) 103 | (replace-vars . my-impostman-walkman-replace-vars) 104 | (header . my-impostman-walkman-header) 105 | (item . my-impostman-walkman-item) 106 | (request . my-impostman-walkman-request) 107 | (footer . my-impostman-walkman-footer) 108 | (end . my-impostman-walkman-end)) 109 | "Emacs walkman output") 110 | ``` 111 | 112 | Keys are fixed symbols and values are [callback functions](#callback-functions). 113 | 114 | A function can be `ignore`, in this case it is simply ignored, for example if you don't have anything to do for `init` and `end`: 115 | 116 | ```elisp 117 | (defconst my-impostman-walkman-alist 118 | '((init . ignore) 119 | (replace-vars . my-impostman-walkman-replace-vars) 120 | (header . my-impostman-walkman-header) 121 | (item . my-impostman-walkman-item) 122 | (request . my-impostman-walkman-request) 123 | (footer . my-impostman-walkman-footer) 124 | (end . ignore)) 125 | "Emacs walkman output") 126 | ``` 127 | 128 | Then you can call for a file: 129 | 130 | ```elisp 131 | (impostman-parse-file "/path/to/collection.json" "/path/to/environment.json" my-impostman-walkman-alist) 132 | ``` 133 | 134 | And for a string: 135 | 136 | ```elisp 137 | (impostman-parse-string "{}" "" my-impostman-walkman-alist) 138 | ``` 139 | 140 | You can also add your output to the list of impostman outputs, so you can use it with `impostman-import-file` and `impostman-import-string`: 141 | 142 | ```elisp 143 | (push '("walkman" . my-impostman-walkman-alist) impostman-outputs-alist) 144 | ``` 145 | 146 | This will put your output at the beginning of the alist, so it will be the default output. 147 | 148 | ### Callback functions 149 | 150 | #### init 151 | 152 | ```elisp 153 | (defun xxx-init (variables) 154 | (...)) 155 | ``` 156 | 157 | Function called when the output buffer is created and before parsing the collection. 158 | 159 | Arguments: 160 | 161 | - `variables` (alist): variables from collection and environment (in reverse order: latest variable read is the first one in alist). 162 | 163 | #### replace-vars 164 | 165 | ```elisp 166 | (defun xxx-replace-vars (string variables) 167 | (...)) 168 | ``` 169 | 170 | Function called to replace Postman variables (format: `{{variable}}`) in a string. It must return a string where the Postman variables have been replaced by the appropriate value (according to the output). 171 | 172 | Note: according to the option `impostman-use-variables`, a variable is either replaced with a reference (by default and the format depends on the output) or directly with its value, if the option is set to nil. 173 | 174 | Arguments: 175 | 176 | - `string` (string): any string 177 | - `variables` (alist): variables from collection and environment (in reverse order: latest variable read is the first one in alist). 178 | 179 | #### header 180 | 181 | ```elisp 182 | (defun xxx-header (name description variables) 183 | (...)) 184 | ``` 185 | 186 | Function called after `init` and before parsing the collection. It must return a string which is inserted in the output buffer. 187 | 188 | Arguments: 189 | 190 | - `name` (string): collection name (`unknown` if not found) 191 | - `description` (string): collection description 192 | - `variables` (alist): variables from collection and environment (in reverse order: latest variable read is the first one in alist). 193 | 194 | #### item 195 | 196 | ```elisp 197 | (defun xxx-item (level name description variables) 198 | (...)) 199 | ``` 200 | 201 | Function called for each item read (a folder in Postman). It must return a string which is inserted in the output buffer. 202 | 203 | Arguments: 204 | 205 | - `level` (integer): folder level (≥ 2) 206 | - `name` (string): item name 207 | - `description` (string): item description 208 | - `variables` (alist): variables from collection and environment (in reverse order: latest variable read is the first one in alist). 209 | 210 | #### request 211 | 212 | ```elisp 213 | (defun xxx-request (description method url headers body variables) 214 | (...)) 215 | ``` 216 | 217 | Function called for each request read. It must return a string which is inserted in the output buffer. 218 | 219 | Arguments: 220 | 221 | - `description` (string): request description 222 | - `method` (string): the HTTP method (`GET`, `POST`, `PUT`, …) 223 | - `url` (string): request URL 224 | - `headers` (alist): request headers (in reverse order: latest header read is the first one in alist) 225 | - `body` (string): request body 226 | - `variables` (alist): variables from collection and environment (in reverse order: latest variable read is the first one in alist). 227 | 228 | #### footer 229 | 230 | ```elisp 231 | (defun xxx-footer (name variables) 232 | (...)) 233 | ``` 234 | 235 | Function called at the end of parsing. It must return a string which is inserted in the output buffer. 236 | 237 | Arguments: 238 | 239 | - `name` (string): collection name (`unknown` if not found) 240 | - `variables` (alist): variables from collection and environment (in reverse order: latest variable read is the first one in alist). 241 | 242 | #### end 243 | 244 | ```elisp 245 | (defun xxx-end (variables) 246 | (...)) 247 | ``` 248 | 249 | Function called at the end. It can be used to enable a major or minor mode. 250 | 251 | Arguments: 252 | 253 | - `variables` (alist): variables from collection and environment (in reverse order: latest variable read is the first one in alist). 254 | 255 | ## Known limitations 256 | 257 | For now the package offers a basic support of Postman collections and environments, the following features are partially implemented: 258 | 259 | - authentication: only `basic` and `apikey` are supported 260 | - body: only `raw` is supported. 261 | 262 | Pull requests are welcome to add missing features. 263 | 264 | ## Copyright 265 | 266 | 267 | Copyright © 2020-2025 [Sébastien Helleu](https://github.com/flashcode) 268 | 269 | This program is free software; you can redistribute it and/or modify 270 | it under the terms of the GNU General Public License as published by 271 | the Free Software Foundation; either version 3 of the License, or 272 | (at your option) any later version. 273 | 274 | This program is distributed in the hope that it will be useful, 275 | but WITHOUT ANY WARRANTY; without even the implied warranty of 276 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 277 | GNU General Public License for more details. 278 | 279 | You should have received a copy of the GNU General Public License 280 | along with this program. If not, see . 281 | 282 | -------------------------------------------------------------------------------- /REUSE.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2025 Sébastien Helleu 2 | # 3 | # SPDX-License-Identifier: GPL-3.0-or-later 4 | 5 | version = 1 6 | 7 | [[annotations]] 8 | path = [ 9 | ".github/ISSUE_TEMPLATE/*.md", 10 | "tests/*.json", 11 | "tests/*.org", 12 | ] 13 | precedence = "override" 14 | SPDX-FileCopyrightText = "2020-2025 Sébastien Helleu " 15 | SPDX-License-Identifier = "GPL-3.0-or-later" 16 | -------------------------------------------------------------------------------- /impostman.el: -------------------------------------------------------------------------------- 1 | ;;; impostman.el --- Import Postman collections -*- lexical-binding: t -*- 2 | 3 | ;; SPDX-FileCopyrightText: 2020-2025 Sébastien Helleu 4 | 5 | ;; SPDX-License-Identifier: GPL-3.0-or-later 6 | 7 | ;; Author: Sébastien Helleu 8 | ;; Maintainer: Sébastien Helleu 9 | ;; Created: 2020-12-24 10 | ;; Keywords: tools 11 | ;; URL: https://github.com/flashcode/impostman 12 | ;; Version: 0.3.0-snapshot 13 | ;; Package-Requires: ((emacs "27.1")) 14 | 15 | ;; This file is not part of GNU Emacs. 16 | 17 | ;; Impostman is free software: you can redistribute it and/or modify 18 | ;; it under the terms of the GNU General Public License as published by 19 | ;; the Free Software Foundation, either version 3 of the License, or 20 | ;; (at your option) any later version. 21 | ;; 22 | ;; Impostman is distributed in the hope that it will be useful, 23 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ;; GNU General Public License for more details. 26 | ;; 27 | ;; You should have received a copy of the GNU General Public License 28 | ;; along with Impostman. If not, see . 29 | ;; 30 | 31 | ;;; Commentary: 32 | 33 | ;; Import Postman collections/environments to use them with your favorite 34 | ;; Emacs HTTP client: 35 | ;; - verb 36 | ;; - restclient 37 | ;; - your custom output. 38 | 39 | ;;; Code: 40 | 41 | (require 'subr-x) 42 | 43 | ;; customization 44 | 45 | (defgroup impostman nil 46 | "Import Postman collections and environments." 47 | :prefix "impostman-" 48 | :group 'tools) 49 | 50 | (defcustom impostman-auth-basic-as-elisp-code t 51 | "Convert Basic authentication header to elisp code for easy edit. 52 | 53 | Example with verb: 54 | Authorization: Basic {{(base64-encode-string 55 | (encode-coding-string \"username:password\" \\='utf-8) t)}} 56 | 57 | Example with restclient: 58 | :auth := (format \"Basic %s\" (base64-encode-string 59 | (encode-coding-string \"username:password\" \\='utf-8) t)) 60 | Authorization: :auth 61 | 62 | If nil, the username and password are directly encoded in base64: 63 | Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=" 64 | :type 'boolean) 65 | 66 | (defcustom impostman-use-variables t 67 | "Keep Postman variables in the output and define variables. 68 | 69 | If nil, no variables are used, they are directly replaced by their values 70 | during the import of collection." 71 | :type 'boolean) 72 | 73 | (defconst impostman-version "0.3.0-snapshot" 74 | "Impostman package version.") 75 | 76 | (defconst impostman-output-verb-alist 77 | '((init . ignore) 78 | (replace-vars . impostman-output-verb-replace-vars) 79 | (header . impostman-output-verb-header) 80 | (item . impostman-output-verb-item) 81 | (request . impostman-output-verb-request) 82 | (footer . impostman-output-verb-footer) 83 | (end . impostman-output-verb-end)) 84 | "Emacs verb output.") 85 | 86 | (defconst impostman-output-restclient-alist 87 | '((init . ignore) 88 | (replace-vars . impostman-output-restclient-replace-vars) 89 | (header . impostman-output-restclient-header) 90 | (item . impostman-output-restclient-item) 91 | (request . impostman-output-restclient-request) 92 | (footer . impostman-output-restclient-footer) 93 | (end . impostman-output-restclient-end)) 94 | "Emacs restclient output.") 95 | 96 | (defcustom impostman-outputs-alist 97 | '(("verb" . impostman-output-verb-alist) 98 | ("restclient" . impostman-output-restclient-alist)) 99 | "Impostman outputs." 100 | :type '(alist :key-type string :value-type function)) 101 | 102 | ;; functions common to all outputs 103 | 104 | (defun impostman-format-comment (comment &optional prefix) 105 | "Format a comment, which can be on multiple lines. 106 | 107 | COMMENT is a string, where multiple lines are separated by \"\\n\". 108 | PREFIX is the prefix to add in front of each line (default is \"# \")." 109 | (let ((comment (or comment "")) 110 | (prefix (or prefix "# "))) 111 | (if (string-empty-p comment) 112 | "" 113 | (concat 114 | prefix 115 | (replace-regexp-in-string "\n" (concat "\n" prefix) comment) 116 | "\n")))) 117 | 118 | (defun impostman-get-auth-basic-plain (authorization) 119 | "Get the plain-text \"username:password\" given an AUTHORIZATION header. 120 | 121 | For example with the value \"Basic dXNlcm5hbWU6cGFzc3dvcmQ=\", 122 | the function returns \"username:password\". 123 | Return nil if the authentication is not Basic or if the base64 is invalid." 124 | (save-match-data 125 | (when (string-match "^Basic \\(.*\\)" authorization) 126 | (ignore-errors (base64-decode-string (match-string 1 authorization)))))) 127 | 128 | ;; verb output 129 | 130 | (defun impostman-output-verb-replace-vars (string variables) 131 | "Replace variables in a string, using verb syntax. 132 | 133 | STRING any string that can contain variables with format \"{{variable}}\". 134 | VARIABLES is an alist with Postman variables." 135 | (if impostman-use-variables 136 | (replace-regexp-in-string 137 | "{{\\([^}]+\\)}}" "{{(verb-var \\1)}}" (or string "")) 138 | (replace-regexp-in-string 139 | "{{[^}]+}}" 140 | (lambda (s) 141 | (let* ((name (substring s 2 -2)) 142 | (var (assoc name variables))) 143 | (if var (cdr var) name))) 144 | (or string "")))) 145 | 146 | (defun impostman-output-verb-header (name description variables) 147 | "Format the verb header. 148 | 149 | NAME is the collection name. 150 | DESCRIPTION is the collection description. 151 | VARIABLES is an alist with Postman variables." 152 | (ignore variables) 153 | (concat 154 | "* " name " :verb:" "\n" 155 | (impostman-format-comment description))) 156 | 157 | (defun impostman-output-verb-item (level name description variables) 158 | "Format a verb item. 159 | 160 | LEVEL is the level. 161 | NAME is the item name. 162 | DESCRIPTION is the item description. 163 | VARIABLES is an alist with Postman variables." 164 | (ignore variables) 165 | (concat 166 | (if (<= level 2) "\n" "") 167 | (make-string (max level 1) ?*) " " name "\n" 168 | (impostman-format-comment description))) 169 | 170 | (defun impostman-output-verb-request (description method url headers body variables) 171 | "Format a verb request. 172 | 173 | DESCRIPTION is the request description. 174 | METHOD is the HTTP method. 175 | URL is the URL. 176 | HEADERS is an alist with HTTP headers. 177 | BODY is the request body. 178 | VARIABLES is an alist with Postman variables." 179 | (ignore variables) 180 | (let (list-headers) 181 | (dolist (header (nreverse headers)) 182 | (let* ((header-name (car header)) 183 | (header-value (cdr header)) 184 | (new-value header-value)) 185 | (when (and impostman-auth-basic-as-elisp-code 186 | (string= header-name "Authorization")) 187 | (let ((auth-plain (impostman-get-auth-basic-plain header-value))) 188 | (when auth-plain 189 | (setq new-value 190 | (concat 191 | "Basic " 192 | "{{(base64-encode-string (encode-coding-string \"" 193 | auth-plain "\" 'utf-8) t)}}"))))) 194 | (push (concat header-name ": " new-value) list-headers))) 195 | (concat 196 | (impostman-format-comment description) 197 | (downcase method) " " url "\n" 198 | (when list-headers 199 | (concat (string-join (nreverse list-headers) "\n") "\n")) 200 | (if (string-empty-p body) "" (concat "\n" body "\n"))))) 201 | 202 | (defun impostman-output-verb-footer (name variables) 203 | "Format the verb footer. 204 | 205 | NAME is the collection name. 206 | VARIABLES is an alist with Postman variables." 207 | (let (list-vars) 208 | (when impostman-use-variables 209 | (dolist (var (nreverse variables)) 210 | (push 211 | (format "# eval: (verb-set-var \"%s\" \"%s\")" (car var) (cdr var)) 212 | list-vars))) 213 | (concat 214 | "\n" 215 | "* End of " name "\n" 216 | "\n" 217 | "# Local Variables:\n" 218 | "# eval: (verb-mode)\n" 219 | (when list-vars 220 | (concat (string-join (nreverse list-vars) "\n") "\n")) 221 | "# End:\n"))) 222 | 223 | (defun impostman-output-verb-end (variables) 224 | "Function evaluated at the end. 225 | 226 | VARIABLES is an alist with Postman variables." 227 | (when (fboundp 'org-mode) 228 | (org-mode)) 229 | (when (fboundp 'verb-mode) 230 | (verb-mode)) 231 | ;; evaluate variables now 232 | (when (and impostman-use-variables (fboundp 'verb-set-var)) 233 | (dolist (var (nreverse variables)) 234 | (verb-set-var (car var) (cdr var))))) 235 | 236 | ;; restclient output 237 | 238 | (defun impostman-output-restclient-replace-vars (string variables) 239 | "Replace variables in a string, using restclient syntax. 240 | 241 | STRING any string that can contain variables with format \"{{variable}}\". 242 | VARIABLES is an alist with Postman variables." 243 | (if impostman-use-variables 244 | (replace-regexp-in-string 245 | "{{\\([^}]+\\)}}" ":\\1" (or string "")) 246 | (replace-regexp-in-string 247 | "{{[^}]+}}" 248 | (lambda (s) 249 | (let* ((name (substring s 2 -2)) 250 | (var (assoc name variables))) 251 | (if var (cdr var) name))) 252 | (or string "")))) 253 | 254 | (defun impostman-output-restclient-header (name description variables) 255 | "Format the restclient header. 256 | 257 | NAME is the collection name. 258 | DESCRIPTION is the collection description. 259 | VARIABLES is an alist with Postman variables." 260 | (let (list-vars) 261 | (when impostman-use-variables 262 | (dolist (var (nreverse variables)) 263 | (push (format ":%s = %s" (car var) (cdr var)) list-vars))) 264 | (concat 265 | "# -*- restclient -*-\n" 266 | "#\n" 267 | "# " name "\n" 268 | (impostman-format-comment description) 269 | "#\n" 270 | (when list-vars 271 | (concat "\n" (string-join (nreverse list-vars) "\n") "\n"))))) 272 | 273 | (defun impostman-output-restclient-item (level name description variables) 274 | "Format a restclient item. 275 | 276 | LEVEL is the level. 277 | NAME is the item name. 278 | DESCRIPTION is the item description. 279 | VARIABLES is an alist with Postman variables." 280 | (ignore variables) 281 | (concat 282 | (if (<= level 2) "\n" "") 283 | (make-string (max level 1) ?#) " " name "\n" 284 | (impostman-format-comment description))) 285 | 286 | (defun impostman-output-restclient-request (description method url headers body variables) 287 | "Format a restclient request. 288 | 289 | DESCRIPTION is the request description. 290 | METHOD is the HTTP method. 291 | URL is the URL. 292 | HEADERS is an alist with HTTP headers. 293 | BODY is the request body. 294 | VARIABLES is an alist with Postman variables." 295 | (ignore variables) 296 | (let (list-variables list-headers) 297 | (dolist (header (nreverse headers)) 298 | (let* ((header-name (car header)) 299 | (header-value (cdr header)) 300 | (new-value header-value)) 301 | (when (and impostman-auth-basic-as-elisp-code 302 | (string= header-name "Authorization")) 303 | (let ((auth-plain (impostman-get-auth-basic-plain header-value))) 304 | (when auth-plain 305 | (push (concat 306 | ":auth := (format \"Basic %s\" " 307 | "(base64-encode-string (encode-coding-string \"" 308 | auth-plain "\" 'utf-8) t))") 309 | list-variables) 310 | (setq new-value ":auth")))) 311 | (push (concat header-name ": " new-value) list-headers))) 312 | (concat 313 | (impostman-format-comment description) 314 | (when list-variables 315 | (concat (string-join (nreverse list-variables) "\n") "\n")) 316 | method " " url "\n" 317 | (when list-headers 318 | (concat (string-join (nreverse list-headers) "\n") "\n")) 319 | (if (string-empty-p body) "" (concat body "\n"))))) 320 | 321 | (defun impostman-output-restclient-footer (name variables) 322 | "Format the restclient footer. 323 | 324 | NAME is the collection name. 325 | VARIABLES is an alist with Postman variables." 326 | (ignore variables) 327 | (concat 328 | "\n" 329 | "# End of " name "\n")) 330 | 331 | (defun impostman-output-restclient-end (variables) 332 | "Function evaluated at the end. 333 | 334 | VARIABLES is an alist with Postman variables." 335 | (ignore variables) 336 | (when (fboundp 'restclient-mode) 337 | (restclient-mode))) 338 | 339 | ;; Postman collection parser 340 | 341 | (defun impostman--build-auth-headers (auth) 342 | "Return an alist with headers, based on the `auth' JSON item. 343 | 344 | AUTH is a hash table." 345 | (let* (headers 346 | (auth (or auth (make-hash-table :test 'equal))) 347 | (auth-type (gethash "type" auth ""))) 348 | (cond ((string= auth-type "basic") 349 | (let (username password (basic (gethash "basic" auth []))) 350 | (dotimes (i (length basic)) 351 | (let* ((item (elt basic i)) 352 | (key (gethash "key" item "")) 353 | (value (gethash "value" item ""))) 354 | (cond ((string= key "username") 355 | (setq username value)) 356 | ((string= key "password") 357 | (setq password value))))) 358 | (when (or username password) 359 | (let ((auth-base64 360 | (base64-encode-string 361 | (encode-coding-string 362 | (concat username ":" password) 'utf-8)))) 363 | (push 364 | (cons "Authorization" (concat "Basic " auth-base64)) 365 | headers))))) 366 | ((string= auth-type "apikey") 367 | (let ((apikey (gethash "apikey" auth [])) 368 | apikey-key apikey-value apikey-in) 369 | (dotimes (i (length apikey)) 370 | (let* ((apikey-item (elt apikey i)) 371 | (key (gethash "key" apikey-item "")) 372 | (value (gethash "value" apikey-item ""))) 373 | (cond ((string= key "key") 374 | (setq apikey-key value)) 375 | ((string= key "value") 376 | (setq apikey-value value)) 377 | ((string= key "in") 378 | (setq apikey-in value))))) 379 | (when (and (not (string= apikey-in "query")) 380 | (or apikey-key apikey-value)) 381 | (push (cons apikey-key apikey-value) headers))))) 382 | (nreverse headers))) 383 | 384 | (defun impostman--build-headers (header) 385 | "Return an alist with headers, based on the `header' JSON item. 386 | 387 | HEADER is a vector with hash tables." 388 | (let (headers) 389 | (dotimes (i (length header)) 390 | (let* ((header-item (elt header i)) 391 | (key (gethash "key" header-item "")) 392 | (value (gethash "value" header-item ""))) 393 | (push (cons key value) headers))) 394 | headers)) 395 | 396 | (defun impostman--build-auth-query-string (auth) 397 | "Return query string parameter to add for authentication as an alist. 398 | 399 | For example: (\"key\" . \"value\"), or nil if there's no query string to add. 400 | 401 | AUTH is a hash table." 402 | (let (query-string-items) 403 | (when auth 404 | (let ((auth-type (gethash "type" auth ""))) 405 | (when (string= auth-type "apikey") 406 | (let ((apikey (gethash "apikey" auth [])) 407 | apikey-key apikey-value apikey-in) 408 | (dotimes (i (length apikey)) 409 | (let* ((apikey-item (elt apikey i)) 410 | (key (gethash "key" apikey-item "")) 411 | (value (gethash "value" apikey-item ""))) 412 | (cond ((string= key "key") 413 | (setq apikey-key value)) 414 | ((string= key "value") 415 | (setq apikey-value value)) 416 | ((string= key "in") 417 | (setq apikey-in value))))) 418 | (when (and (string= apikey-in "query") 419 | (or apikey-key apikey-value)) 420 | (push (cons apikey-key apikey-value) query-string-items)))))) 421 | (nreverse query-string-items))) 422 | 423 | (defun impostman--add-query-string-items-to-url (url query-string-items) 424 | "Return the URL with updated query string parameters. 425 | 426 | URL is a string. 427 | QUERY-STRING-ITEMS is nil or an alist with query strings to add." 428 | (dolist (query-string query-string-items) 429 | (setq url (concat 430 | url 431 | (if (string-match-p "\\?" url) "&" "?") 432 | (car query-string) 433 | "=" 434 | (cdr query-string)))) 435 | url) 436 | 437 | (defun impostman--build-variables (values) 438 | "Return alist with variables using Postman collection/environment. 439 | 440 | VALUES is the \"variable\" read from collection (vector) or \"values\" read 441 | from environment (vector) (or concatenation of both)." 442 | (let (variables) 443 | (dotimes (i (length (or values []))) 444 | (let* ((item (elt values i)) 445 | (key (gethash "key" item "")) 446 | (value (gethash "value" item "")) 447 | (enabled (equal t (gethash "enabled" item t))) 448 | (disabled (equal t (gethash "disabled" item nil)))) 449 | (when (and enabled (not disabled)) 450 | (push (cons key value) variables)))) 451 | variables)) 452 | 453 | (defun impostman--parse-item (items level variables output-alist) 454 | "Parse a Postman collection item. 455 | 456 | ITEMS is the \"item\" read from collection (vector). 457 | LEVEL is the level. 458 | VARIABLES is an alist with Postman variables. 459 | OUTPUT-ALIST is an alist with the output callbacks." 460 | (dotimes (i (length items)) 461 | (let* ((item (elt items i)) 462 | (name (gethash "name" item "")) 463 | (description (gethash "description" item "")) 464 | (subitem (gethash "item" item)) 465 | (request (gethash "request" item))) 466 | (insert (funcall (alist-get 'item output-alist) 467 | level name description variables)) 468 | (if subitem 469 | (impostman--parse-item subitem (1+ level) variables output-alist) 470 | (when request 471 | (let* ((description (gethash "description" request "")) 472 | (auth (gethash "auth" request (make-hash-table))) 473 | (method (gethash "method" request "")) 474 | (header (gethash "header" request [])) 475 | (body (gethash 476 | "raw" 477 | (gethash "body" request (make-hash-table)) "")) 478 | (url (gethash 479 | "raw" 480 | (gethash "url" request (make-hash-table)) "")) 481 | (auth-headers (impostman--build-auth-headers auth)) 482 | (other-headers (impostman--build-headers header)) 483 | (headers (append other-headers auth-headers)) 484 | (replace-vars (alist-get 'replace-vars output-alist))) 485 | (setq url (impostman--add-query-string-items-to-url 486 | url 487 | (impostman--build-auth-query-string auth))) 488 | (dolist (header headers) 489 | (setf 490 | (car header) (funcall replace-vars (car header) variables) 491 | (cdr header) (funcall replace-vars (cdr header) variables))) 492 | (let ((method2 (funcall replace-vars method variables)) 493 | (url2 (funcall replace-vars url variables)) 494 | (body2 (funcall replace-vars body variables))) 495 | (insert (funcall 496 | (alist-get 'request output-alist) 497 | description method2 url2 headers body2 variables))))))))) 498 | 499 | (defun impostman--parse-json (collection environment output-alist) 500 | "Parse a Postman collection using an optional Postman environment. 501 | 502 | COLLECTION is a hash table with the Postman collection (parsed JSON). 503 | ENVIRONMENT is a hash table with the Postman environment (parsed JSON). 504 | OUTPUT-ALIST is an alist with the output callbacks." 505 | (let* ((name (gethash "name" 506 | (gethash "info" collection (make-hash-table)) 507 | "unknown")) 508 | (description (gethash "description" 509 | (gethash "info" 510 | collection (make-hash-table)) "")) 511 | (item (gethash "item" collection [])) 512 | (variable (gethash "variable" collection [])) 513 | (values (gethash "values" environment [])) 514 | (all-variables (impostman--build-variables (vconcat 515 | variable values)))) 516 | (pop-to-buffer (generate-new-buffer (concat name ".org"))) 517 | (funcall (alist-get 'init output-alist) all-variables) 518 | (insert (funcall (alist-get 'header output-alist) 519 | name description all-variables)) 520 | (impostman--parse-item item 2 all-variables output-alist) 521 | (insert (funcall (alist-get 'footer output-alist) name all-variables)) 522 | (goto-char (point-min)) 523 | (funcall (alist-get 'end output-alist) all-variables) 524 | values)) 525 | 526 | ;;;###autoload 527 | (defun impostman-parse-file (collection environment output-alist) 528 | "Parse a file with a Postman collection. 529 | 530 | COLLECTION is a Postman collection filename. 531 | ENVIRONMENT is a Postman environment filename (optional). 532 | OUTPUT-ALIST is an alist with the output callbacks." 533 | (let (json_col (json_env (make-hash-table :test 'equal))) 534 | (with-temp-buffer 535 | (insert-file-contents collection) 536 | (setq json_col (json-parse-buffer))) 537 | (unless (string-empty-p (or environment "")) 538 | (with-temp-buffer 539 | (insert-file-contents environment) 540 | (setq json_env (json-parse-buffer)))) 541 | (impostman--parse-json json_col json_env output-alist))) 542 | 543 | ;;;###autoload 544 | (defun impostman-parse-string (collection environment output-alist) 545 | "Parse a string with a Postman collection. 546 | 547 | COLLECTION is a string with a Postman collection. 548 | ENVIRONMENT is a string with a Postman environment (optional). 549 | OUTPUT-ALIST is an alist with the output callbacks." 550 | (let ((json_col (json-parse-string collection)) 551 | (json_env (if (string-empty-p (or environment "")) 552 | (make-hash-table :test 'equal) 553 | (json-parse-string environment)))) 554 | (impostman--parse-json json_col json_env output-alist))) 555 | 556 | ;; Postman collection import 557 | 558 | (defun impostman-read-collection-filename () 559 | "Read Postman collection filename." 560 | (interactive) 561 | (read-file-name "Postman collection file (JSON): ")) 562 | 563 | (defun impostman-read-environment-filename () 564 | "Read Postman environment filename." 565 | (interactive) 566 | (let (insert-default-directory) 567 | (read-file-name "Postman environment file (JSON, optional): "))) 568 | 569 | (defun impostman-read-output () 570 | "Read Postman output type. 571 | 572 | It which must be a key from alist `impostman-outputs-alist'. 573 | 574 | If the alist size is 1, the value is immediately returned without asking 575 | anything." 576 | (interactive) 577 | (let* ((default (caar impostman-outputs-alist)) 578 | (prompt (concat "Output format (default is " default "): "))) 579 | (if (= (length impostman-outputs-alist) 1) 580 | default 581 | (completing-read 582 | prompt impostman-outputs-alist nil t nil nil default)))) 583 | 584 | (defun impostman--get-output-alist (name) 585 | "Get output alist with a given NAME. 586 | 587 | A key with this name must exist in `impostman-outputs-alist'." 588 | (let ((output-alist (assoc name impostman-outputs-alist))) 589 | (if output-alist 590 | (symbol-value (cdr output-alist)) 591 | (error "Output \"%s\" is not supported" name)))) 592 | 593 | ;;;###autoload 594 | (defun impostman-import-file (&optional collection environment output-name) 595 | "Import a file with a Postman collection. 596 | 597 | COLLECTION is a Postman collection filename. 598 | ENVIRONMENT is a Postman environment filename (optional). 599 | OUTPUT-NAME is a string with the desired output (eg: \"verb\")." 600 | (interactive) 601 | (let* ((collection (or collection (impostman-read-collection-filename))) 602 | (environment (or environment (impostman-read-environment-filename))) 603 | (output-name (or output-name (impostman-read-output))) 604 | (output-alist (impostman--get-output-alist output-name))) 605 | (impostman-parse-file collection environment output-alist))) 606 | 607 | ;;;###autoload 608 | (defun impostman-import-string (collection environment &optional output-name) 609 | "Import a string with a Postman collection. 610 | 611 | COLLECTION is a string with a Postman collection. 612 | ENVIRONMENT is a string with a Postman environment (optional). 613 | OUTPUT-NAME is a string with the desired output (eg: \"verb\")." 614 | (interactive) 615 | (let* ((output-name (or output-name (impostman-read-output))) 616 | (output-alist (impostman--get-output-alist output-name))) 617 | (impostman-parse-string collection environment output-alist))) 618 | 619 | ;; version 620 | 621 | ;;;###autoload 622 | (defun impostman-version (&optional print-dest) 623 | "Return the Impostman version. 624 | 625 | PRINT-DEST is the output stream, by default the echo area. 626 | 627 | With \\[universal-argument] prefix, output is in the current buffer." 628 | (interactive (list (if current-prefix-arg (current-buffer) t))) 629 | (when (called-interactively-p 'any) 630 | (princ (format "impostman %s" impostman-version) print-dest)) 631 | impostman-version) 632 | 633 | (provide 'impostman) 634 | 635 | ;;; impostman.el ends here 636 | -------------------------------------------------------------------------------- /tests/custom.org: -------------------------------------------------------------------------------- 1 | * httpbin :test: 2 | # A collection to test with httpbin: 3 | # - HTTP methods 4 | # - Authentication 5 | # - Anything. 6 | 7 | VAR(var1) = value1_collection 8 | VAR(url) = https://httpbin.org 9 | VAR(variable_delete) = value_delete 10 | VAR(variable_get) = value_get 11 | VAR(header-api-key) = x-api-key 12 | VAR(query-api-key) = key 13 | VAR(api-key) = my_secret_key 14 | VAR(var1) = value1_env 15 | 16 | ** http_methods 17 | *** delete 18 | # A DELETE request. 19 | DELETE $(url)/delete?search=$(variable_delete) 20 | x-test: the_value 21 | x-test2: second_value 22 | *** get 23 | # A GET request. 24 | GET $(url)/get?search=$(variable_get) 25 | x-test: the_value 26 | x-test2: second_value 27 | x-unknown: $(unknown) 28 | *** patch 29 | # A PATCH request. 30 | PATCH $(url)/patch?search=test 31 | x-test: the_value 32 | x-test2: second_value 33 | *** post 34 | # A POST request. 35 | POST $(url)/post?search=test 36 | x-test: the_value 37 | x-test2: second_value 38 | { 39 | "test": "value", 40 | "list": [ 41 | "first", 42 | "second" 43 | ], 44 | "var1": "$(var1)" 45 | } 46 | *** put 47 | # A PUT request. 48 | PUT $(url)/put?search=test 49 | x-test: the_value 50 | x-test2: second_value 51 | 52 | ** auth 53 | *** auth basic 54 | # A request with HTTP basic authentication. 55 | GET $(url)/basic-auth/user/secret 56 | Authorization: Basic dXNlcjpzZWNyZXQ= 57 | 58 | ** anything 59 | *** get, auth with api key (header) 60 | # A GET request with API key authentication (sent as HTTP header). 61 | GET $(url)/anything 62 | $(header-api-key): $(api-key) 63 | x-test: the_value 64 | { 65 | "test": "value" 66 | } 67 | *** get, auth with api key (query string) 68 | # A GET request with API key authentication (sent as query string). 69 | GET $(url)/anything?$(query-api-key)=$(api-key) 70 | x-test: the_value 71 | { 72 | "test": "value" 73 | } 74 | 75 | * End of httpbin 76 | -------------------------------------------------------------------------------- /tests/custom_no_vars.org: -------------------------------------------------------------------------------- 1 | * httpbin :test: 2 | # A collection to test with httpbin: 3 | # - HTTP methods 4 | # - Authentication 5 | # - Anything. 6 | 7 | ** http_methods 8 | *** delete 9 | # A DELETE request. 10 | DELETE https://httpbin.org/delete?search=value_delete 11 | x-test: the_value 12 | x-test2: second_value 13 | *** get 14 | # A GET request. 15 | GET https://httpbin.org/get?search=value_get 16 | x-test: the_value 17 | x-test2: second_value 18 | x-unknown: unknown 19 | *** patch 20 | # A PATCH request. 21 | PATCH https://httpbin.org/patch?search=test 22 | x-test: the_value 23 | x-test2: second_value 24 | *** post 25 | # A POST request. 26 | POST https://httpbin.org/post?search=test 27 | x-test: the_value 28 | x-test2: second_value 29 | { 30 | "test": "value", 31 | "list": [ 32 | "first", 33 | "second" 34 | ], 35 | "var1": "value1_env" 36 | } 37 | *** put 38 | # A PUT request. 39 | PUT https://httpbin.org/put?search=test 40 | x-test: the_value 41 | x-test2: second_value 42 | 43 | ** auth 44 | *** auth basic 45 | # A request with HTTP basic authentication. 46 | GET https://httpbin.org/basic-auth/user/secret 47 | Authorization: Basic dXNlcjpzZWNyZXQ= 48 | 49 | ** anything 50 | *** get, auth with api key (header) 51 | # A GET request with API key authentication (sent as HTTP header). 52 | GET https://httpbin.org/anything 53 | x-api-key: my_secret_key 54 | x-test: the_value 55 | { 56 | "test": "value" 57 | } 58 | *** get, auth with api key (query string) 59 | # A GET request with API key authentication (sent as query string). 60 | GET https://httpbin.org/anything?key=my_secret_key 61 | x-test: the_value 62 | { 63 | "test": "value" 64 | } 65 | 66 | * End of httpbin 67 | -------------------------------------------------------------------------------- /tests/httpbin.postman_collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "info": { 3 | "_postman_id": "8d20f87a-e93f-43a1-9a17-9fef0cff30e0", 4 | "name": "httpbin", 5 | "description": "A collection to test with httpbin:\n- HTTP methods\n- Authentication\n- Anything.", 6 | "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" 7 | }, 8 | "item": [ 9 | { 10 | "name": "http_methods", 11 | "item": [ 12 | { 13 | "name": "delete", 14 | "request": { 15 | "method": "DELETE", 16 | "header": [ 17 | { 18 | "key": "x-test", 19 | "value": "the_value", 20 | "description": "description of header x-test", 21 | "type": "text" 22 | }, 23 | { 24 | "key": "x-test2", 25 | "value": "second_value", 26 | "description": "description of header x-test2", 27 | "type": "text" 28 | } 29 | ], 30 | "url": { 31 | "raw": "{{url}}/delete?search={{variable_delete}}", 32 | "host": [ 33 | "{{url}}" 34 | ], 35 | "path": [ 36 | "delete" 37 | ], 38 | "query": [ 39 | { 40 | "key": "search", 41 | "value": "{{variable_delete}}" 42 | } 43 | ] 44 | }, 45 | "description": "A DELETE request." 46 | }, 47 | "response": [] 48 | }, 49 | { 50 | "name": "get", 51 | "request": { 52 | "method": "GET", 53 | "header": [ 54 | { 55 | "key": "x-test", 56 | "value": "the_value", 57 | "description": "description of header x-test", 58 | "type": "text" 59 | }, 60 | { 61 | "key": "x-test2", 62 | "value": "second_value", 63 | "description": "description of header x-test2", 64 | "type": "text" 65 | }, 66 | { 67 | "key": "x-unknown", 68 | "value": "{{unknown}}", 69 | "description": "header with unknown variable", 70 | "type": "text" 71 | } 72 | ], 73 | "url": { 74 | "raw": "{{url}}/get?search={{variable_get}}", 75 | "host": [ 76 | "{{url}}" 77 | ], 78 | "path": [ 79 | "get" 80 | ], 81 | "query": [ 82 | { 83 | "key": "search", 84 | "value": "{{variable_get}}" 85 | } 86 | ] 87 | }, 88 | "description": "A GET request." 89 | }, 90 | "response": [] 91 | }, 92 | { 93 | "name": "patch", 94 | "request": { 95 | "method": "PATCH", 96 | "header": [ 97 | { 98 | "key": "x-test", 99 | "value": "the_value", 100 | "description": "description of header x-test", 101 | "type": "text" 102 | }, 103 | { 104 | "key": "x-test2", 105 | "value": "second_value", 106 | "description": "description of header x-test2", 107 | "type": "text" 108 | } 109 | ], 110 | "url": { 111 | "raw": "{{url}}/patch?search=test", 112 | "host": [ 113 | "{{url}}" 114 | ], 115 | "path": [ 116 | "patch" 117 | ], 118 | "query": [ 119 | { 120 | "key": "search", 121 | "value": "test" 122 | } 123 | ] 124 | }, 125 | "description": "A PATCH request." 126 | }, 127 | "response": [] 128 | }, 129 | { 130 | "name": "post", 131 | "request": { 132 | "method": "POST", 133 | "header": [ 134 | { 135 | "key": "x-test", 136 | "value": "the_value", 137 | "description": "description of header x-test", 138 | "type": "text" 139 | }, 140 | { 141 | "key": "x-test2", 142 | "value": "second_value", 143 | "description": "description of header x-test2", 144 | "type": "text" 145 | } 146 | ], 147 | "body": { 148 | "mode": "raw", 149 | "raw": "{\n \"test\": \"value\",\n \"list\": [\n \"first\",\n \"second\"\n ],\n \"var1\": \"{{var1}}\"\n}" 150 | }, 151 | "url": { 152 | "raw": "{{url}}/post?search=test", 153 | "host": [ 154 | "{{url}}" 155 | ], 156 | "path": [ 157 | "post" 158 | ], 159 | "query": [ 160 | { 161 | "key": "search", 162 | "value": "test" 163 | } 164 | ] 165 | }, 166 | "description": "A POST request." 167 | }, 168 | "response": [] 169 | }, 170 | { 171 | "name": "put", 172 | "request": { 173 | "method": "PUT", 174 | "header": [ 175 | { 176 | "key": "x-test", 177 | "value": "the_value", 178 | "description": "description of header x-test", 179 | "type": "text" 180 | }, 181 | { 182 | "key": "x-test2", 183 | "value": "second_value", 184 | "description": "description of header x-test2", 185 | "type": "text" 186 | } 187 | ], 188 | "url": { 189 | "raw": "{{url}}/put?search=test", 190 | "host": [ 191 | "{{url}}" 192 | ], 193 | "path": [ 194 | "put" 195 | ], 196 | "query": [ 197 | { 198 | "key": "search", 199 | "value": "test" 200 | } 201 | ] 202 | }, 203 | "description": "A PUT request." 204 | }, 205 | "response": [] 206 | } 207 | ] 208 | }, 209 | { 210 | "name": "auth", 211 | "item": [ 212 | { 213 | "name": "auth basic", 214 | "request": { 215 | "auth": { 216 | "type": "basic", 217 | "basic": [ 218 | { 219 | "key": "password", 220 | "value": "secret", 221 | "type": "string" 222 | }, 223 | { 224 | "key": "username", 225 | "value": "user", 226 | "type": "string" 227 | }, 228 | { 229 | "key": "saveHelperData", 230 | "type": "any" 231 | }, 232 | { 233 | "key": "showPassword", 234 | "value": false, 235 | "type": "boolean" 236 | } 237 | ] 238 | }, 239 | "method": "GET", 240 | "header": [], 241 | "url": { 242 | "raw": "{{url}}/basic-auth/user/secret", 243 | "host": [ 244 | "{{url}}" 245 | ], 246 | "path": [ 247 | "basic-auth", 248 | "user", 249 | "secret" 250 | ] 251 | }, 252 | "description": "A request with HTTP basic authentication." 253 | }, 254 | "response": [] 255 | } 256 | ] 257 | }, 258 | { 259 | "name": "anything", 260 | "item": [ 261 | { 262 | "name": "get, auth with api key (header)", 263 | "protocolProfileBehavior": { 264 | "disableBodyPruning": true 265 | }, 266 | "request": { 267 | "auth": { 268 | "type": "apikey", 269 | "apikey": [ 270 | { 271 | "key": "value", 272 | "value": "{{api-key}}", 273 | "type": "string" 274 | }, 275 | { 276 | "key": "key", 277 | "value": "{{header-api-key}}", 278 | "type": "string" 279 | } 280 | ] 281 | }, 282 | "method": "GET", 283 | "header": [ 284 | { 285 | "key": "x-test", 286 | "value": "the_value", 287 | "description": "A test header.", 288 | "type": "text" 289 | } 290 | ], 291 | "body": { 292 | "mode": "raw", 293 | "raw": "{\n \"test\": \"value\"\n}" 294 | }, 295 | "url": { 296 | "raw": "{{url}}/anything", 297 | "host": [ 298 | "{{url}}" 299 | ], 300 | "path": [ 301 | "anything" 302 | ] 303 | }, 304 | "description": "A GET request with API key authentication (sent as HTTP header)." 305 | }, 306 | "response": [] 307 | }, 308 | { 309 | "name": "get, auth with api key (query string)", 310 | "protocolProfileBehavior": { 311 | "disableBodyPruning": true 312 | }, 313 | "request": { 314 | "auth": { 315 | "type": "apikey", 316 | "apikey": [ 317 | { 318 | "key": "value", 319 | "value": "{{api-key}}", 320 | "type": "string" 321 | }, 322 | { 323 | "key": "key", 324 | "value": "{{query-api-key}}", 325 | "type": "string" 326 | }, 327 | { 328 | "key": "in", 329 | "value": "query", 330 | "type": "string" 331 | } 332 | ] 333 | }, 334 | "method": "GET", 335 | "header": [ 336 | { 337 | "description": "A test header.", 338 | "key": "x-test", 339 | "type": "text", 340 | "value": "the_value" 341 | } 342 | ], 343 | "body": { 344 | "mode": "raw", 345 | "raw": "{\n \"test\": \"value\"\n}" 346 | }, 347 | "url": { 348 | "raw": "{{url}}/anything", 349 | "host": [ 350 | "{{url}}" 351 | ], 352 | "path": [ 353 | "anything" 354 | ] 355 | }, 356 | "description": "A GET request with API key authentication (sent as query string)." 357 | }, 358 | "response": [] 359 | } 360 | ] 361 | } 362 | ], 363 | "event": [ 364 | { 365 | "listen": "prerequest", 366 | "script": { 367 | "type": "text/javascript", 368 | "exec": [ 369 | "" 370 | ] 371 | } 372 | }, 373 | { 374 | "listen": "test", 375 | "script": { 376 | "type": "text/javascript", 377 | "exec": [ 378 | "" 379 | ] 380 | } 381 | } 382 | ], 383 | "variable": [ 384 | { 385 | "key": "var1", 386 | "value": "value1_collection" 387 | }, 388 | { 389 | "key": "var2-not-enabled", 390 | "value": "value2_collection", 391 | "disabled": true 392 | } 393 | ] 394 | } -------------------------------------------------------------------------------- /tests/httpbin.postman_environment.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "36154963-69d3-40dc-8dfd-32f3edda9bd8", 3 | "name": "httpbin", 4 | "values": [ 5 | { 6 | "key": "url", 7 | "value": "https://httpbin.org", 8 | "enabled": true 9 | }, 10 | { 11 | "key": "variable_delete", 12 | "value": "value_delete", 13 | "enabled": true 14 | }, 15 | { 16 | "key": "variable_get", 17 | "value": "value_get", 18 | "enabled": true 19 | }, 20 | { 21 | "key": "header-api-key", 22 | "value": "x-api-key", 23 | "enabled": true 24 | }, 25 | { 26 | "key": "query-api-key", 27 | "value": "key", 28 | "enabled": true 29 | }, 30 | { 31 | "key": "api-key", 32 | "value": "my_secret_key", 33 | "enabled": true 34 | }, 35 | { 36 | "key": "var1", 37 | "value": "value1_env", 38 | "enabled": true 39 | }, 40 | { 41 | "key": "not-enabled", 42 | "value": "some_value", 43 | "enabled": false 44 | } 45 | ], 46 | "_postman_variable_scope": "environment", 47 | "_postman_exported_at": "2021-08-14T10:06:37.886Z", 48 | "_postman_exported_using": "Postman/8.10.0" 49 | } -------------------------------------------------------------------------------- /tests/impostman-test.el: -------------------------------------------------------------------------------- 1 | ;;; impostman-test.el --- Test suite for impostman -*- lexical-binding: t -*- 2 | 3 | ;; SPDX-FileCopyrightText: 2020-2025 Sébastien Helleu 4 | 5 | ;; SPDX-License-Identifier: GPL-3.0-or-later 6 | 7 | ;; Author: Sébastien Helleu 8 | ;; Maintainer: Sébastien Helleu 9 | ;; Created: 2020-12-24 10 | ;; Keywords: tools 11 | ;; URL: https://github.com/flashcode/impostman 12 | ;; Version: 0.3.0-snapshot 13 | ;; Package-Requires: ((emacs "27.1")) 14 | 15 | ;; This file is not part of GNU Emacs. 16 | 17 | ;; Impostman is free software: you can redistribute it and/or modify 18 | ;; it under the terms of the GNU General Public License as published by 19 | ;; the Free Software Foundation, either version 3 of the License, or 20 | ;; (at your option) any later version. 21 | ;; 22 | ;; Impostman is distributed in the hope that it will be useful, 23 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | ;; GNU General Public License for more details. 26 | ;; 27 | ;; You should have received a copy of the GNU General Public License 28 | ;; along with Impostman. If not, see . 29 | ;; 30 | 31 | ;;; Commentary: 32 | 33 | ;; Test suite for impostman. 34 | 35 | ;;; Code: 36 | 37 | (require 'ert) 38 | (require 'impostman) 39 | 40 | (defun impostman-test--get-file-contents (filename) 41 | "Get contents of a file. 42 | 43 | FILENAME is a complete path to a file." 44 | (with-temp-buffer 45 | (insert-file-contents filename) 46 | (buffer-string))) 47 | 48 | (ert-deftest impostman-test-format-comment () 49 | "Test the format of comment." 50 | ;; without prefix: default is "# " 51 | (should (equal (impostman-format-comment nil) 52 | "")) 53 | (should (equal (impostman-format-comment "") 54 | "")) 55 | (should (equal (impostman-format-comment "Test") 56 | (string-join '("# Test" "") "\n"))) 57 | (should (equal (impostman-format-comment 58 | (string-join '("Test" "Line 2") "\n")) 59 | (string-join '("# Test" "# Line 2" "") "\n"))) 60 | (should (equal (impostman-format-comment 61 | (string-join '("Test" "Line 2" "Line 3") "\n")) 62 | (string-join '("# Test" "# Line 2" "# Line 3" "") "\n"))) 63 | 64 | ;; with a prefix 65 | (should (equal (impostman-format-comment "" ";; ") 66 | "")) 67 | (should (equal (impostman-format-comment "Test" ";; ") 68 | (string-join '(";; Test" "") "\n"))) 69 | (should (equal (impostman-format-comment 70 | (string-join '("Test" "Line 2") "\n") ";; ") 71 | (string-join '(";; Test" ";; Line 2" "") "\n"))) 72 | (should (equal (impostman-format-comment 73 | (string-join '("Test" "Line 2" "Line 3") "\n") ";; ") 74 | (string-join '(";; Test" ";; Line 2" ";; Line 3" "") "\n")))) 75 | 76 | (ert-deftest impostman-test-get-auth-basic-plain () 77 | "Test the base64 decoding of Authorization Basic header." 78 | (should (equal (impostman-get-auth-basic-plain "") 79 | nil)) 80 | (should (equal (impostman-get-auth-basic-plain "test") 81 | nil)) 82 | (should (equal (impostman-get-auth-basic-plain "Basic a") 83 | nil)) 84 | (should (equal (impostman-get-auth-basic-plain 85 | "Basic dXNlcm5hbWU6cGFzc3dvcmQ=") 86 | "username:password"))) 87 | 88 | (ert-deftest impostman-test-output-verb-replace-vars () 89 | "Test the format of variables with verb syntax." 90 | (let ((impostman-use-variables t)) 91 | (should (equal (impostman-output-verb-replace-vars 92 | nil nil) 93 | "")) 94 | (should (equal (impostman-output-verb-replace-vars 95 | "" nil) 96 | "")) 97 | (should (equal (impostman-output-verb-replace-vars 98 | "Test" nil) 99 | "Test")) 100 | (should (equal (impostman-output-verb-replace-vars 101 | "Test {{var1}} and {{var2}}" nil) 102 | "Test {{(verb-var var1)}} and {{(verb-var var2)}}")) 103 | (should (equal (impostman-output-verb-replace-vars 104 | "Test {{var1}} and {{var2}}" 105 | '(("var1" . "value1") ("var2" . "value2"))) 106 | "Test {{(verb-var var1)}} and {{(verb-var var2)}}"))) 107 | (let (impostman-use-variables) 108 | (should (equal (impostman-output-verb-replace-vars 109 | "Test {{var1}}, {{var2}} and {{var3}}" 110 | '(("var1" . "value1") ("var2" . "value2"))) 111 | "Test value1, value2 and var3")))) 112 | 113 | (ert-deftest impostman-test-output-verb-header () 114 | "Test the output of verb header." 115 | (should (equal (impostman-output-verb-header 116 | "test" (string-join '("Description" "Line 2") "\n") nil) 117 | (string-join 118 | '("* test :verb:" 119 | "# Description" 120 | "# Line 2" 121 | "") 122 | "\n")))) 123 | 124 | (ert-deftest impostman-test-output-verb-item () 125 | "Test the output of verb item." 126 | (should (equal (impostman-output-verb-item 0 "test" "" nil) 127 | (string-join '("" "* test" "") "\n"))) 128 | (should (equal (impostman-output-verb-item 1 "test" "" nil) 129 | (string-join '("" "* test" "") "\n"))) 130 | (should (equal (impostman-output-verb-item 2 "test" "" nil) 131 | (string-join '("" "** test" "") "\n"))) 132 | (should (equal (impostman-output-verb-item 3 "test" "" nil) 133 | (string-join '("*** test" "") "\n"))) 134 | (should (equal (impostman-output-verb-item 135 | 0 136 | "test" 137 | (string-join '("line 2" "end.") "\n") 138 | nil) 139 | (string-join '("" "* test" "# line 2" "# end." "") "\n"))) 140 | (should (equal (impostman-output-verb-item 141 | 1 142 | "test" 143 | (string-join '("line 2" "end.") "\n") 144 | nil) 145 | (string-join '("" "* test" "# line 2" "# end." "") "\n"))) 146 | (should (equal (impostman-output-verb-item 147 | 2 148 | "test" 149 | (string-join '("line 2" "end.") "\n") 150 | nil) 151 | (string-join '("" "** test" "# line 2" "# end." "") "\n"))) 152 | (should (equal (impostman-output-verb-item 153 | 3 154 | "test" 155 | (string-join '("line 2" "end.") "\n") 156 | nil) 157 | (string-join '("*** test" "# line 2" "# end." "") "\n")))) 158 | 159 | (ert-deftest impostman-test-output-verb-request () 160 | "Test the output of verb request." 161 | (let ((impostman-auth-basic-as-elisp-code t)) 162 | (should (equal (impostman-output-verb-request 163 | "" 164 | "GET" 165 | "users" 166 | nil 167 | "" 168 | nil) 169 | (string-join '("get users" "") "\n"))) 170 | (should (equal (impostman-output-verb-request 171 | "" 172 | "POST" 173 | "users" 174 | nil 175 | "{\"login\": \"admin\"}" 176 | nil) 177 | (string-join 178 | '("post users" 179 | "" 180 | "{\"login\": \"admin\"}" 181 | "") 182 | "\n"))) 183 | (should (equal (impostman-output-verb-request 184 | "" 185 | "POST" 186 | "users" 187 | '(("Authorization" . "token")) 188 | "{\"login\": \"admin\"}" 189 | nil) 190 | (string-join 191 | '("post users" 192 | "Authorization: token" 193 | "" 194 | "{\"login\": \"admin\"}" 195 | "") 196 | "\n"))) 197 | (should (equal (impostman-output-verb-request 198 | (string-join '("Description" "end.") "\n") 199 | "POST" 200 | "users" 201 | '(("header" . "value") ("Authorization" . "token")) 202 | "{\"login\": \"admin\"}" 203 | nil) 204 | (string-join 205 | '("# Description" 206 | "# end." 207 | "post users" 208 | "Authorization: token" 209 | "header: value" 210 | "" 211 | "{\"login\": \"admin\"}" 212 | "") 213 | "\n"))) 214 | (should (equal (impostman-output-verb-request 215 | (string-join '("Description" "end.") "\n") 216 | "POST" 217 | "users" 218 | '(("header" . "value") 219 | ("Authorization" . "Basic dXNlcjE6UGFzc3dvcmQh")) 220 | "{\"login\": \"admin\"}" 221 | nil) 222 | (string-join 223 | '("# Description" 224 | "# end." 225 | "post users" 226 | "Authorization: Basic {{(base64-encode-string (encode-coding-string \"user1:Password!\" 'utf-8) t)}}" 227 | "header: value" 228 | "" 229 | "{\"login\": \"admin\"}" 230 | "") 231 | "\n")))) 232 | (let (impostman-auth-basic-as-elisp-code) 233 | (should (equal (impostman-output-verb-request 234 | (string-join '("Description" "end.") "\n") 235 | "POST" 236 | "users" 237 | '(("header" . "value") 238 | ("Authorization" . "Basic dXNlcjE6UGFzc3dvcmQh")) 239 | "{\"login\": \"admin\"}" 240 | nil) 241 | (string-join 242 | '("# Description" 243 | "# end." 244 | "post users" 245 | "Authorization: Basic dXNlcjE6UGFzc3dvcmQh" 246 | "header: value" 247 | "" 248 | "{\"login\": \"admin\"}" 249 | "") 250 | "\n"))))) 251 | 252 | (ert-deftest impostman-test-output-verb-footer () 253 | "Test the output of verb footer." 254 | (let ((impostman-use-variables t)) 255 | (should (equal (impostman-output-verb-footer "test" nil) 256 | (string-join 257 | '("" 258 | "* End of test" 259 | "" 260 | "# Local Variables:" 261 | "# eval: (verb-mode)" 262 | "# End:" 263 | "") 264 | "\n"))) 265 | (should (equal (impostman-output-verb-footer 266 | "test" 267 | '(("var2" . "value2") ("var1" . "value1"))) 268 | (string-join 269 | '("" 270 | "* End of test" 271 | "" 272 | "# Local Variables:" 273 | "# eval: (verb-mode)" 274 | "# eval: (verb-set-var \"var1\" \"value1\")" 275 | "# eval: (verb-set-var \"var2\" \"value2\")" 276 | "# End:" 277 | "") 278 | "\n")))) 279 | (let (impostman-use-variables) 280 | (should (equal (impostman-output-verb-footer 281 | "test" 282 | '(("var2" . "value2") ("var1" . "value1"))) 283 | (string-join 284 | '("" 285 | "* End of test" 286 | "" 287 | "# Local Variables:" 288 | "# eval: (verb-mode)" 289 | "# End:" 290 | "") 291 | "\n"))))) 292 | 293 | (ert-deftest impostman-test-output-restclient-replace-vars () 294 | "Test the format of variables with restclient syntax." 295 | (let ((impostman-use-variables t)) 296 | (should (equal (impostman-output-restclient-replace-vars 297 | nil nil) 298 | "")) 299 | (should (equal (impostman-output-restclient-replace-vars 300 | "" nil) 301 | "")) 302 | (should (equal (impostman-output-restclient-replace-vars 303 | "Test" nil) 304 | "Test")) 305 | (should (equal (impostman-output-restclient-replace-vars 306 | "Test {{var1}} and {{var2}}" nil) 307 | "Test :var1 and :var2")) 308 | (should (equal (impostman-output-restclient-replace-vars 309 | "Test {{var1}} and {{var2}}" 310 | '(("var1" . "value1") ("var2" . "value2"))) 311 | "Test :var1 and :var2"))) 312 | (let (impostman-use-variables) 313 | (should (equal (impostman-output-restclient-replace-vars 314 | "Test {{var1}}, {{var2}} and {{var3}}" 315 | '(("var1" . "value1") ("var2" . "value2"))) 316 | "Test value1, value2 and var3")))) 317 | 318 | (ert-deftest impostman-test-output-restclient-header () 319 | "Test the output of restclient header." 320 | (let ((impostman-use-variables t)) 321 | (should (equal (impostman-output-restclient-header 322 | "test" (string-join '("Description" "Line 2") "\n") nil) 323 | (string-join 324 | '("# -*- restclient -*-" 325 | "#" 326 | "# test" 327 | "# Description" 328 | "# Line 2" 329 | "#" 330 | "") 331 | "\n"))) 332 | (should (equal (impostman-output-restclient-header 333 | "test" 334 | (string-join '("Description" "Line 2") "\n") 335 | '(("var2" . "value2") ("var1" . "value1"))) 336 | (string-join 337 | '("# -*- restclient -*-" 338 | "#" 339 | "# test" 340 | "# Description" 341 | "# Line 2" 342 | "#" 343 | "" 344 | ":var1 = value1" 345 | ":var2 = value2" 346 | "") 347 | "\n")))) 348 | (let (impostman-use-variables) 349 | (should (equal (impostman-output-restclient-header 350 | "test" 351 | (string-join '("Description" "Line 2") "\n") 352 | '(("var1" . "value1") ("var2" . "value2"))) 353 | (string-join 354 | '("# -*- restclient -*-" 355 | "#" 356 | "# test" 357 | "# Description" 358 | "# Line 2" 359 | "#" 360 | "") 361 | "\n"))))) 362 | 363 | (ert-deftest impostman-test-output-restclient-item () 364 | "Test the output of restclient item." 365 | (should (equal (impostman-output-restclient-item 0 "test" "" nil) 366 | (string-join '("" "# test" "") "\n"))) 367 | (should (equal (impostman-output-restclient-item 1 "test" "" nil) 368 | (string-join '("" "# test" "") "\n"))) 369 | (should (equal (impostman-output-restclient-item 2 "test" "" nil) 370 | (string-join '("" "## test" "") "\n"))) 371 | (should (equal (impostman-output-restclient-item 3 "test" "" nil) 372 | (string-join '("### test" "") "\n"))) 373 | (should (equal (impostman-output-restclient-item 374 | 0 "test" (string-join '("Description" "end.") "\n") nil) 375 | (string-join 376 | '("" 377 | "# test" 378 | "# Description" 379 | "# end." 380 | "") 381 | "\n"))) 382 | (should (equal (impostman-output-restclient-item 383 | 1 "test" (string-join '("Description" "end.") "\n") nil) 384 | (string-join 385 | '("" 386 | "# test" 387 | "# Description" 388 | "# end." 389 | "") 390 | "\n"))) 391 | (should (equal (impostman-output-restclient-item 392 | 2 "test" (string-join '("Description" "end.") "\n") nil) 393 | (string-join 394 | '("" 395 | "## test" 396 | "# Description" 397 | "# end." 398 | "") 399 | "\n"))) 400 | (should (equal (impostman-output-restclient-item 401 | 3 "test" (string-join '("Description" "end.") "\n") nil) 402 | (string-join 403 | '("### test" 404 | "# Description" 405 | "# end." 406 | "") 407 | "\n")))) 408 | 409 | (ert-deftest impostman-test-output-restclient-request () 410 | "Test the output of restclient request." 411 | (let ((impostman-auth-basic-as-elisp-code t)) 412 | (should (equal (impostman-output-restclient-request 413 | "" 414 | "GET" 415 | "users" 416 | nil 417 | "" 418 | nil) 419 | (string-join 420 | '("GET users" 421 | "") 422 | "\n"))) 423 | (should (equal (impostman-output-restclient-request 424 | "" 425 | "GET" 426 | "users" 427 | nil 428 | "{\"login\": \"admin\"}" 429 | nil) 430 | (string-join 431 | '("GET users" 432 | "{\"login\": \"admin\"}" 433 | "") 434 | "\n"))) 435 | (should (equal (impostman-output-restclient-request 436 | "" 437 | "GET" 438 | "users" 439 | '(("Authorization" . "token")) 440 | "{\"login\": \"admin\"}" 441 | nil) 442 | (string-join 443 | '("GET users" 444 | "Authorization: token" 445 | "{\"login\": \"admin\"}" 446 | "") 447 | "\n"))) 448 | (should (equal (impostman-output-restclient-request 449 | (string-join '("Description" "end.") "\n") 450 | "GET" 451 | "users" 452 | '(("header" . "value") ("Authorization" . "token")) 453 | "{\"login\": \"admin\"}" 454 | nil) 455 | (string-join 456 | '("# Description" 457 | "# end." 458 | "GET users" 459 | "Authorization: token" 460 | "header: value" 461 | "{\"login\": \"admin\"}" 462 | "") 463 | "\n"))) 464 | (should (equal (impostman-output-restclient-request 465 | (string-join '("Description" "end.") "\n") 466 | "GET" 467 | "users" 468 | '(("header" . "value") 469 | ("Authorization" . "Basic dXNlcjE6UGFzc3dvcmQh")) 470 | "{\"login\": \"admin\"}" 471 | nil) 472 | (string-join 473 | '("# Description" 474 | "# end." 475 | ":auth := (format \"Basic %s\" (base64-encode-string (encode-coding-string \"user1:Password!\" 'utf-8) t))" 476 | "GET users" 477 | "Authorization: :auth" 478 | "header: value" 479 | "{\"login\": \"admin\"}" 480 | "") 481 | "\n")))) 482 | (let (impostman-auth-basic-as-elisp-code) 483 | (should (equal (impostman-output-restclient-request 484 | (string-join '("Description" "end.") "\n") 485 | "GET" 486 | "users" 487 | '(("header" . "value") 488 | ("Authorization" . "Basic dXNlcjE6UGFzc3dvcmQh")) 489 | "{\"login\": \"admin\"}" 490 | nil) 491 | (string-join 492 | '("# Description" 493 | "# end." 494 | "GET users" 495 | "Authorization: Basic dXNlcjE6UGFzc3dvcmQh" 496 | "header: value" 497 | "{\"login\": \"admin\"}" 498 | "") 499 | "\n"))))) 500 | 501 | (ert-deftest impostman-test-output-restclient-footer () 502 | "Test the output of restclient footer." 503 | (should (equal (impostman-output-restclient-footer "test" nil) 504 | (string-join 505 | '("" 506 | "# End of test" 507 | "") 508 | "\n")))) 509 | 510 | (ert-deftest impostman-test-build-auth-headers () 511 | "Test the build of auth headers." 512 | (let ((auth (make-hash-table :test 'equal)) 513 | (username #s(hash-table test equal data ("key" "username" 514 | "value" "user1"))) 515 | (password #s(hash-table test equal data ("key" "password" 516 | "value" "Password!"))) 517 | (apikey-key #s(hash-table test equal data ("key" "key" 518 | "value" "apikey"))) 519 | (apikey-value #s(hash-table test equal data ("key" "value" 520 | "value" "1a2b3c4d"))) 521 | (apikey-in #s(hash-table test equal data ("key" "in" 522 | "value" "query")))) 523 | ;; no auth 524 | (should (equal (impostman--build-auth-headers nil) 525 | nil)) 526 | (should (equal (impostman--build-auth-headers 527 | #s(hash-table test equal)) 528 | nil)) 529 | (should (equal (impostman--build-auth-headers 530 | #s(hash-table test equal data ("type" "unknown"))) 531 | nil)) 532 | (should (equal (impostman--build-auth-headers 533 | #s(hash-table test equal data ("type" "basic"))) 534 | nil)) 535 | (should (equal (impostman--build-auth-headers 536 | #s(hash-table test equal data ("type" "basic" 537 | "basic" []))) 538 | nil)) 539 | (should (equal (impostman--build-auth-headers auth) 540 | nil)) 541 | ;; test basic 542 | (puthash "type" "basic" auth) 543 | (puthash "basic" [] auth) 544 | (puthash "basic" (vector username) auth) 545 | (should (equal (impostman--build-auth-headers auth) 546 | `(("Authorization" . 547 | ,(concat "Basic " 548 | (base64-encode-string "user1:")))))) 549 | (puthash "basic" (vector password) auth) 550 | (should (equal (impostman--build-auth-headers auth) 551 | `(("Authorization" . 552 | ,(concat "Basic " 553 | (base64-encode-string ":Password!")))))) 554 | (puthash "basic" (vector username password) auth) 555 | (should (equal (impostman--build-auth-headers auth) 556 | `(("Authorization" . 557 | ,(concat "Basic " 558 | (base64-encode-string "user1:Password!")))))) 559 | ;; test apikey 560 | (clrhash auth) 561 | (puthash "type" "apikey" auth) 562 | (puthash "apikey" (vector apikey-key apikey-value) auth) 563 | (should (equal (impostman--build-auth-headers auth) 564 | '(("apikey" . "1a2b3c4d")))) 565 | ;; test apikey in query-string (no header) 566 | (puthash "apikey" (vector apikey-key apikey-value apikey-in) auth) 567 | (should (equal (impostman--build-auth-headers auth) 568 | nil)))) 569 | 570 | (ert-deftest impostman-test-build-headers () 571 | "Test the build of headers." 572 | (let ((header1 #s(hash-table test equal data ("key" "header1" 573 | "value" "value1"))) 574 | (header2 #s(hash-table test equal data ("key" "X-header2" 575 | "value" "the value 2")))) 576 | ;; no header 577 | (should (equal (impostman--build-headers nil) 578 | nil)) 579 | (should (equal (impostman--build-headers []) 580 | nil)) 581 | ;; test headers 582 | (should (equal (impostman--build-headers (vector header1 header2)) 583 | '(("X-header2" . "the value 2") 584 | ("header1" . "value1")))) 585 | (should (equal (impostman--build-headers 586 | (vector header1 header2 header1 header2)) 587 | '(("X-header2" . "the value 2") 588 | ("header1" . "value1") 589 | ("X-header2" . "the value 2") 590 | ("header1" . "value1")))))) 591 | 592 | (ert-deftest impostman-test-build-auth-query-string () 593 | "Test build of query-string parameter for authentication." 594 | (let ((auth (make-hash-table :test 'equal)) 595 | (apikey-key #s(hash-table test equal data ("key" "key" 596 | "value" "apikey"))) 597 | (apikey-value #s(hash-table test equal data ("key" "value" 598 | "value" "1a2b3c4d"))) 599 | (apikey-in #s(hash-table test equal data ("key" "in" 600 | "value" "query")))) 601 | ;; test apikey as header (no query-string) 602 | (puthash "type" "apikey" auth) 603 | (puthash "apikey" (vector apikey-key apikey-value) auth) 604 | (should (equal (impostman--build-auth-query-string auth) 605 | nil)) 606 | ;; test apikey as query-string 607 | (puthash "apikey" (vector apikey-key apikey-value apikey-in) auth) 608 | (should (equal (impostman--build-auth-query-string auth) 609 | '(("apikey" . "1a2b3c4d")))))) 610 | 611 | (ert-deftest impostman-test-add-query-string-items-to-url () 612 | "Test add of query-string items to an URL." 613 | (should (equal (impostman--add-query-string-items-to-url 614 | "https://example.com" nil) 615 | "https://example.com")) 616 | (should (equal (impostman--add-query-string-items-to-url 617 | "https://example.com" '(("apikey" . "1a2b3c4d"))) 618 | "https://example.com?apikey=1a2b3c4d")) 619 | (should (equal (impostman--add-query-string-items-to-url 620 | "https://example.com?a=1" '(("apikey" . "1a2b3c4d"))) 621 | "https://example.com?a=1&apikey=1a2b3c4d"))) 622 | 623 | (ert-deftest impostman-test-build-variables () 624 | "Test build of variables." 625 | (let ((var1 #s(hash-table test equal data ("key" "var1" 626 | "value" "value1"))) 627 | (var2 #s(hash-table test equal data ("key" "var2" 628 | "value" "value2" 629 | "enabled" t))) 630 | (var3 #s(hash-table test equal data ("key" "var3" 631 | "value" "value3" 632 | "enabled" :false))) 633 | (var4 #s(hash-table test equal data ("key" "var4" 634 | "value" "value4" 635 | "disabled" t))) 636 | (var1-new #s(hash-table test equal data ("key" "var1" 637 | "value" "value1_new")))) 638 | (should (equal (impostman--build-variables nil) 639 | nil)) 640 | (should (equal (impostman--build-variables []) 641 | nil)) 642 | (should (equal (impostman--build-variables (vector var1)) 643 | '(("var1" . "value1")))) 644 | (should (equal (impostman--build-variables (vector var1 var1)) 645 | '(("var1" . "value1") ("var1" . "value1")))) 646 | (should (equal (impostman--build-variables (vector var1 var2)) 647 | '(("var2" . "value2") ("var1" . "value1")))) 648 | (should (equal (impostman--build-variables (vector var2 var1)) 649 | '(("var1" . "value1") ("var2" . "value2")))) 650 | (should (equal (impostman--build-variables (vector var2 var1 var3 var4)) 651 | '(("var1" . "value1") ("var2" . "value2")))) 652 | (should (equal (impostman--build-variables 653 | (vector var2 var1 var3 var4 var1-new)) 654 | '(("var1" . "value1_new") ("var1" . "value1") 655 | ("var2" . "value2")))))) 656 | 657 | (ert-deftest impostman-test-parse-item () 658 | "Test parsing of an item." 659 | (let ((item1 (make-hash-table :test 'equal)) 660 | (request1 (make-hash-table :test 'equal)) 661 | (url (make-hash-table :test 'equal)) 662 | (body (make-hash-table :test 'equal)) 663 | (auth (make-hash-table :test 'equal)) 664 | (username #s(hash-table test equal data ("key" "username" 665 | "value" "user1"))) 666 | (password #s(hash-table test equal data ("key" "password" 667 | "value" "Password!"))) 668 | (header1 #s(hash-table test equal data ("key" "header1" 669 | "value" "value1"))) 670 | (header2 #s(hash-table test equal data ("key" "X-header2" 671 | "value" "the value 2")))) 672 | (puthash "name" "item1" item1) 673 | ;; item without request 674 | (with-temp-buffer 675 | (impostman--parse-item (vector item1) 2 nil impostman-output-verb-alist) 676 | (should (equal (buffer-string) 677 | (string-join 678 | '("" 679 | "** item1" 680 | "") 681 | "\n")))) 682 | ;; add description in item 683 | (puthash "description" 684 | (string-join '("The description" "line 2.") "\n") item1) 685 | (with-temp-buffer 686 | (impostman--parse-item (vector item1) 2 nil impostman-output-verb-alist) 687 | (should (equal (buffer-string) 688 | (string-join 689 | '("" 690 | "** item1" 691 | "# The description" 692 | "# line 2." 693 | "") 694 | "\n")))) 695 | ;; item with a request 696 | (puthash "method" "POST" request1) 697 | (puthash "raw" "https://example.com" url) 698 | (puthash "url" url request1) 699 | (puthash "request" request1 item1) 700 | (with-temp-buffer 701 | (impostman--parse-item (vector item1) 2 nil impostman-output-verb-alist) 702 | (should (equal (buffer-string) 703 | (string-join 704 | '("" 705 | "** item1" 706 | "# The description" 707 | "# line 2." 708 | "post https://example.com" 709 | "") 710 | "\n")))) 711 | ;; add description in request 712 | (puthash "description" "Some info on request" request1) 713 | (with-temp-buffer 714 | (impostman--parse-item (vector item1) 2 nil impostman-output-verb-alist) 715 | (should (equal (buffer-string) 716 | (string-join 717 | '("" 718 | "** item1" 719 | "# The description" 720 | "# line 2." 721 | "# Some info on request" 722 | "post https://example.com" 723 | "") 724 | "\n")))) 725 | ;; add auth in request 726 | (puthash "type" "basic" auth) 727 | (puthash "basic" [] auth) 728 | (puthash "basic" (vector username password) auth) 729 | (puthash "auth" auth request1) 730 | (with-temp-buffer 731 | (impostman--parse-item (vector item1) 2 nil impostman-output-verb-alist) 732 | (should (equal (buffer-string) 733 | (string-join 734 | '("" 735 | "** item1" 736 | "# The description" 737 | "# line 2." 738 | "# Some info on request" 739 | "post https://example.com" 740 | "Authorization: Basic {{(base64-encode-string (encode-coding-string \"user1:Password!\" 'utf-8) t)}}" 741 | "") 742 | "\n")))) 743 | ;; add 2 headers in request 744 | (puthash "header" (vector header1 header2) request1) 745 | (with-temp-buffer 746 | (impostman--parse-item (vector item1) 2 nil impostman-output-verb-alist) 747 | (should (equal (buffer-string) 748 | (string-join 749 | '("" 750 | "** item1" 751 | "# The description" 752 | "# line 2." 753 | "# Some info on request" 754 | "post https://example.com" 755 | "Authorization: Basic {{(base64-encode-string (encode-coding-string \"user1:Password!\" 'utf-8) t)}}" 756 | "header1: value1" 757 | "X-header2: the value 2" 758 | "") 759 | "\n")))) 760 | ;; add body in request 761 | (puthash "raw" "{\"key\": \"data\"}" body) 762 | (puthash "body" body request1) 763 | (with-temp-buffer 764 | (impostman--parse-item (vector item1) 2 nil impostman-output-verb-alist) 765 | (should (equal (buffer-string) 766 | (string-join 767 | '("" 768 | "** item1" 769 | "# The description" 770 | "# line 2." 771 | "# Some info on request" 772 | "post https://example.com" 773 | "Authorization: Basic {{(base64-encode-string (encode-coding-string \"user1:Password!\" 'utf-8) t)}}" 774 | "header1: value1" 775 | "X-header2: the value 2" 776 | "" 777 | "{\"key\": \"data\"}" 778 | "") 779 | "\n")))))) 780 | 781 | (ert-deftest impostman-test-parse-json () 782 | "Test parsing of a JSON collection." 783 | (let ((collection (make-hash-table :test 'equal)) 784 | (info (make-hash-table :test 'equal)) 785 | (col-var1 #s(hash-table test equal data ("key" "var1" 786 | "value" "value1_col"))) 787 | (col-var2 #s(hash-table test equal data ("key" "var2-not-enabled" 788 | "value" "value2_col" 789 | "disabled" t))) 790 | (environment (make-hash-table :test 'equal)) 791 | (env-var1 #s(hash-table test equal data ("key" "var1" 792 | "value" "value1_env" 793 | "enabled" t))) 794 | (env-var2 #s(hash-table test equal data ("key" "var2-not-enabled" 795 | "value" "value2_env" 796 | "enabled" nil)))) 797 | ;; empty collection / environment 798 | (save-excursion 799 | (impostman--parse-json collection environment impostman-output-verb-alist) 800 | (should (string-prefix-p "unknown.org" (buffer-name))) 801 | (let ((result (buffer-string))) 802 | (should (equal result 803 | (string-join 804 | '("* unknown :verb:" 805 | "" 806 | "* End of unknown" 807 | "" 808 | "# Local Variables:" 809 | "# eval: (verb-mode)" 810 | "# End:" 811 | "") 812 | "\n")))) 813 | (kill-this-buffer)) 814 | ;; add a name in collection 815 | (puthash "name" "my_collection" info) 816 | (puthash "info" info collection) 817 | (save-excursion 818 | (impostman--parse-json collection environment impostman-output-verb-alist) 819 | (should (string-prefix-p "my_collection.org" (buffer-name))) 820 | (let ((result (buffer-string))) 821 | (should (equal result 822 | (string-join 823 | '("* my_collection :verb:" 824 | "" 825 | "* End of my_collection" 826 | "" 827 | "# Local Variables:" 828 | "# eval: (verb-mode)" 829 | "# End:" 830 | "") 831 | "\n")))) 832 | (kill-this-buffer)) 833 | ;; add a description in collection 834 | (puthash "description" (string-join '("Description" "Line 2") "\n") info) 835 | (save-excursion 836 | (impostman--parse-json collection environment impostman-output-verb-alist) 837 | (should (string-prefix-p "my_collection.org" (buffer-name))) 838 | (let ((result (buffer-string))) 839 | (should (equal result 840 | (string-join 841 | '("* my_collection :verb:" 842 | "# Description" 843 | "# Line 2" 844 | "" 845 | "* End of my_collection" 846 | "" 847 | "# Local Variables:" 848 | "# eval: (verb-mode)" 849 | "# End:" 850 | "") 851 | "\n")))) 852 | (kill-this-buffer)) 853 | ;; add variables 854 | (puthash "variable" (vector col-var1 col-var2) collection) 855 | (save-excursion 856 | (impostman--parse-json collection environment impostman-output-verb-alist) 857 | (should (string-prefix-p "my_collection.org" (buffer-name))) 858 | (let ((result (buffer-string))) 859 | (should (equal result 860 | (string-join 861 | '("* my_collection :verb:" 862 | "# Description" 863 | "# Line 2" 864 | "" 865 | "* End of my_collection" 866 | "" 867 | "# Local Variables:" 868 | "# eval: (verb-mode)" 869 | "# eval: (verb-set-var \"var1\" \"value1_col\")" 870 | "# End:" 871 | "") 872 | "\n")))) 873 | (kill-this-buffer)) 874 | ;; add an environment 875 | (puthash "values" (vector env-var1 env-var2) environment) 876 | (save-excursion 877 | (impostman--parse-json collection environment impostman-output-verb-alist) 878 | (should (string-prefix-p "my_collection.org" (buffer-name))) 879 | (let ((result (buffer-string))) 880 | (should (equal result 881 | (string-join 882 | '("* my_collection :verb:" 883 | "# Description" 884 | "# Line 2" 885 | "" 886 | "* End of my_collection" 887 | "" 888 | "# Local Variables:" 889 | "# eval: (verb-mode)" 890 | "# eval: (verb-set-var \"var1\" \"value1_col\")" 891 | "# eval: (verb-set-var \"var1\" \"value1_env\")" 892 | "# End:" 893 | "") 894 | "\n")))) 895 | (kill-this-buffer)))) 896 | 897 | (defun impostman-test-output-custom-init (variables) 898 | "Initialize custom output. 899 | 900 | VARIABLES is an alist with Postman variables." 901 | (ignore variables)) 902 | 903 | (defun impostman-test-output-custom-replace-vars (string variables) 904 | "Format variables for custom output. 905 | 906 | STRING is any string. 907 | VARIABLES is an alist with Postman variables." 908 | (if impostman-use-variables 909 | (replace-regexp-in-string 910 | "{{\\([^}]+\\)}}" "$(\\1)" (or string "")) 911 | (replace-regexp-in-string 912 | "{{[^}]+}}" 913 | (lambda (s) 914 | (let* ((name (substring s 2 -2)) 915 | (var (assoc name variables))) 916 | (if var (cdr var) name))) 917 | (or string "")))) 918 | 919 | (defun impostman-test-output-custom-header (name description variables) 920 | "Format header for custom output. 921 | 922 | NAME is the collection name. 923 | DESCRIPTION is the collection description. 924 | VARIABLES is an alist with Postman variables." 925 | (let (list-vars) 926 | (when impostman-use-variables 927 | (dolist (var (nreverse variables)) 928 | (push (format "VAR(%s) = %s" (car var) (cdr var)) list-vars))) 929 | (concat 930 | "* " name " :test:" "\n" 931 | (impostman-format-comment description) 932 | (when list-vars 933 | (concat "\n" (string-join (nreverse list-vars) "\n") "\n"))))) 934 | 935 | (defun impostman-test-output-custom-item (level name description variables) 936 | "Format item for custom output. 937 | 938 | LEVEL is the level. 939 | NAME is the item name. 940 | DESCRIPTION is the item description. 941 | VARIABLES is an alist with Postman variables." 942 | (ignore variables) 943 | (concat 944 | (if (<= level 2) "\n" "") 945 | (make-string (max level 1) ?*) " " name "\n" 946 | (impostman-format-comment description))) 947 | 948 | (defun impostman-test-output-custom-request (description method url headers body variables) 949 | "Format request for custom output. 950 | 951 | DESCRIPTION is the request description. 952 | METHOD is the HTTP method. 953 | URL is the URL. 954 | HEADERS is an alist with HTTP headers. 955 | BODY is the request body. 956 | VARIABLES is an alist with Postman variables." 957 | (ignore variables) 958 | (let (list-headers) 959 | (dolist (header (nreverse headers)) 960 | (push (format "%s: %s" (car header) (cdr header)) list-headers)) 961 | (concat 962 | (impostman-format-comment description) 963 | method " " url "\n" 964 | (when list-headers 965 | (concat (string-join (nreverse list-headers) "\n") "\n")) 966 | (if (string-empty-p body) "" (concat body "\n"))))) 967 | 968 | (defun impostman-test-output-custom-footer (name variables) 969 | "Format footer for custom output. 970 | 971 | NAME is the collection name. 972 | VARIABLES is an alist with Postman variables." 973 | (ignore variables) 974 | (concat "\n" "* End of " name "\n")) 975 | 976 | (defun impostman-test-output-custom-end (variables) 977 | "End of custom output. 978 | 979 | VARIABLES is an alist with Postman variables." 980 | (ignore variables)) 981 | 982 | (ert-deftest impostman-test-import-file () 983 | "Test import of a file with a Postman collection." 984 | (defvar impostman-test-output-custom-alist 985 | '((init . impostman-test-output-custom-init) 986 | (replace-vars . impostman-test-output-custom-replace-vars) 987 | (header . impostman-test-output-custom-header) 988 | (item . impostman-test-output-custom-item) 989 | (request . impostman-test-output-custom-request) 990 | (footer . impostman-test-output-custom-footer) 991 | (end . impostman-test-output-custom-end))) 992 | (let* ((verb-output 993 | (impostman-test--get-file-contents "verb.org")) 994 | (verb-no-vars-output 995 | (impostman-test--get-file-contents "verb_no_vars.org")) 996 | (restclient-output 997 | (impostman-test--get-file-contents "restclient.org")) 998 | (restclient-no-vars-output 999 | (impostman-test--get-file-contents "restclient_no_vars.org")) 1000 | (custom-output 1001 | (impostman-test--get-file-contents "custom.org")) 1002 | (custom-no-vars-output 1003 | (impostman-test--get-file-contents "custom_no_vars.org")) 1004 | (impostman-outputs-alist 1005 | '(("verb" . impostman-output-verb-alist) 1006 | ("restclient" . impostman-output-restclient-alist) 1007 | ("custom" . impostman-test-output-custom-alist)))) 1008 | (let ((impostman-use-variables t)) 1009 | (save-excursion 1010 | (impostman-import-file "httpbin.postman_collection.json" 1011 | "httpbin.postman_environment.json" 1012 | "verb") 1013 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1014 | (let ((result (buffer-string))) 1015 | (should (equal result verb-output))) 1016 | (kill-this-buffer)) 1017 | (save-excursion 1018 | (impostman-import-file "httpbin.postman_collection.json" 1019 | "httpbin.postman_environment.json" 1020 | "restclient") 1021 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1022 | (let ((result (buffer-string))) 1023 | (should (equal result restclient-output))) 1024 | (kill-this-buffer)) 1025 | (save-excursion 1026 | (impostman-import-file "httpbin.postman_collection.json" 1027 | "httpbin.postman_environment.json" 1028 | "custom") 1029 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1030 | (let ((result (buffer-string))) 1031 | (should (equal result custom-output))) 1032 | (kill-this-buffer))) 1033 | (let (impostman-use-variables) 1034 | (save-excursion 1035 | (impostman-import-file "httpbin.postman_collection.json" 1036 | "httpbin.postman_environment.json" 1037 | "verb") 1038 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1039 | (let ((result (buffer-string))) 1040 | (should (equal result verb-no-vars-output))) 1041 | (kill-this-buffer)) 1042 | (save-excursion 1043 | (impostman-import-file "httpbin.postman_collection.json" 1044 | "httpbin.postman_environment.json" 1045 | "restclient") 1046 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1047 | (let ((result (buffer-string))) 1048 | (should (equal result restclient-no-vars-output))) 1049 | (kill-this-buffer)) 1050 | (save-excursion 1051 | (impostman-import-file "httpbin.postman_collection.json" 1052 | "httpbin.postman_environment.json" 1053 | "custom") 1054 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1055 | (let ((result (buffer-string))) 1056 | (should (equal result custom-no-vars-output))) 1057 | (kill-this-buffer)))) 1058 | (makunbound 'impostman-output-test-alist)) 1059 | 1060 | (ert-deftest impostman-test-import-string () 1061 | "Test import of a string with a Postman collection." 1062 | (defvar impostman-test-output-custom-alist 1063 | '((init . impostman-test-output-custom-init) 1064 | (replace-vars . impostman-test-output-custom-replace-vars) 1065 | (header . impostman-test-output-custom-header) 1066 | (item . impostman-test-output-custom-item) 1067 | (request . impostman-test-output-custom-request) 1068 | (footer . impostman-test-output-custom-footer) 1069 | (end . impostman-test-output-custom-end))) 1070 | (let* ((collection 1071 | (impostman-test--get-file-contents "httpbin.postman_collection.json")) 1072 | (environment 1073 | (impostman-test--get-file-contents "httpbin.postman_environment.json")) 1074 | (verb-output 1075 | (impostman-test--get-file-contents "verb.org")) 1076 | (verb-no-vars-output 1077 | (impostman-test--get-file-contents "verb_no_vars.org")) 1078 | (restclient-output 1079 | (impostman-test--get-file-contents "restclient.org")) 1080 | (restclient-no-vars-output 1081 | (impostman-test--get-file-contents "restclient_no_vars.org")) 1082 | (custom-output 1083 | (impostman-test--get-file-contents "custom.org")) 1084 | (custom-no-vars-output 1085 | (impostman-test--get-file-contents "custom_no_vars.org")) 1086 | (impostman-outputs-alist 1087 | '(("verb" . impostman-output-verb-alist) 1088 | ("restclient" . impostman-output-restclient-alist) 1089 | ("custom" . impostman-test-output-custom-alist)))) 1090 | (let ((impostman-use-variables t)) 1091 | (save-excursion 1092 | (impostman-import-string collection environment "verb") 1093 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1094 | (let ((result (buffer-string))) 1095 | (should (equal result verb-output))) 1096 | (kill-this-buffer)) 1097 | (save-excursion 1098 | (impostman-import-string collection environment "restclient") 1099 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1100 | (let ((result (buffer-string))) 1101 | (should (equal result restclient-output))) 1102 | (kill-this-buffer)) 1103 | (save-excursion 1104 | (impostman-import-string collection environment "custom") 1105 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1106 | (let ((result (buffer-string))) 1107 | (should (equal result custom-output))) 1108 | (kill-this-buffer))) 1109 | (let (impostman-use-variables) 1110 | (save-excursion 1111 | (impostman-import-string collection environment "verb") 1112 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1113 | (let ((result (buffer-string))) 1114 | (should (equal result verb-no-vars-output))) 1115 | (kill-this-buffer)) 1116 | (save-excursion 1117 | (impostman-import-string collection environment "restclient") 1118 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1119 | (let ((result (buffer-string))) 1120 | (should (equal result restclient-no-vars-output))) 1121 | (kill-this-buffer)) 1122 | (save-excursion 1123 | (impostman-import-string collection environment "custom") 1124 | (should (string-prefix-p "httpbin.org" (buffer-name))) 1125 | (let ((result (buffer-string))) 1126 | (should (equal result custom-no-vars-output))) 1127 | (kill-this-buffer)))) 1128 | (makunbound 'impostman-output-test-alist)) 1129 | 1130 | (ert-deftest impostman-test-version () 1131 | "Test Impostman version." 1132 | (should (equal (impostman-version) impostman-version))) 1133 | 1134 | (provide 'impostman-test) 1135 | 1136 | ;;; impostman-test.el ends here 1137 | -------------------------------------------------------------------------------- /tests/restclient.org: -------------------------------------------------------------------------------- 1 | # -*- restclient -*- 2 | # 3 | # httpbin 4 | # A collection to test with httpbin: 5 | # - HTTP methods 6 | # - Authentication 7 | # - Anything. 8 | # 9 | 10 | :var1 = value1_collection 11 | :url = https://httpbin.org 12 | :variable_delete = value_delete 13 | :variable_get = value_get 14 | :header-api-key = x-api-key 15 | :query-api-key = key 16 | :api-key = my_secret_key 17 | :var1 = value1_env 18 | 19 | ## http_methods 20 | ### delete 21 | # A DELETE request. 22 | DELETE :url/delete?search=:variable_delete 23 | x-test: the_value 24 | x-test2: second_value 25 | ### get 26 | # A GET request. 27 | GET :url/get?search=:variable_get 28 | x-test: the_value 29 | x-test2: second_value 30 | x-unknown: :unknown 31 | ### patch 32 | # A PATCH request. 33 | PATCH :url/patch?search=test 34 | x-test: the_value 35 | x-test2: second_value 36 | ### post 37 | # A POST request. 38 | POST :url/post?search=test 39 | x-test: the_value 40 | x-test2: second_value 41 | { 42 | "test": "value", 43 | "list": [ 44 | "first", 45 | "second" 46 | ], 47 | "var1": ":var1" 48 | } 49 | ### put 50 | # A PUT request. 51 | PUT :url/put?search=test 52 | x-test: the_value 53 | x-test2: second_value 54 | 55 | ## auth 56 | ### auth basic 57 | # A request with HTTP basic authentication. 58 | :auth := (format "Basic %s" (base64-encode-string (encode-coding-string "user:secret" 'utf-8) t)) 59 | GET :url/basic-auth/user/secret 60 | Authorization: :auth 61 | 62 | ## anything 63 | ### get, auth with api key (header) 64 | # A GET request with API key authentication (sent as HTTP header). 65 | GET :url/anything 66 | :header-api-key: :api-key 67 | x-test: the_value 68 | { 69 | "test": "value" 70 | } 71 | ### get, auth with api key (query string) 72 | # A GET request with API key authentication (sent as query string). 73 | GET :url/anything?:query-api-key=:api-key 74 | x-test: the_value 75 | { 76 | "test": "value" 77 | } 78 | 79 | # End of httpbin 80 | -------------------------------------------------------------------------------- /tests/restclient_no_vars.org: -------------------------------------------------------------------------------- 1 | # -*- restclient -*- 2 | # 3 | # httpbin 4 | # A collection to test with httpbin: 5 | # - HTTP methods 6 | # - Authentication 7 | # - Anything. 8 | # 9 | 10 | ## http_methods 11 | ### delete 12 | # A DELETE request. 13 | DELETE https://httpbin.org/delete?search=value_delete 14 | x-test: the_value 15 | x-test2: second_value 16 | ### get 17 | # A GET request. 18 | GET https://httpbin.org/get?search=value_get 19 | x-test: the_value 20 | x-test2: second_value 21 | x-unknown: unknown 22 | ### patch 23 | # A PATCH request. 24 | PATCH https://httpbin.org/patch?search=test 25 | x-test: the_value 26 | x-test2: second_value 27 | ### post 28 | # A POST request. 29 | POST https://httpbin.org/post?search=test 30 | x-test: the_value 31 | x-test2: second_value 32 | { 33 | "test": "value", 34 | "list": [ 35 | "first", 36 | "second" 37 | ], 38 | "var1": "value1_env" 39 | } 40 | ### put 41 | # A PUT request. 42 | PUT https://httpbin.org/put?search=test 43 | x-test: the_value 44 | x-test2: second_value 45 | 46 | ## auth 47 | ### auth basic 48 | # A request with HTTP basic authentication. 49 | :auth := (format "Basic %s" (base64-encode-string (encode-coding-string "user:secret" 'utf-8) t)) 50 | GET https://httpbin.org/basic-auth/user/secret 51 | Authorization: :auth 52 | 53 | ## anything 54 | ### get, auth with api key (header) 55 | # A GET request with API key authentication (sent as HTTP header). 56 | GET https://httpbin.org/anything 57 | x-api-key: my_secret_key 58 | x-test: the_value 59 | { 60 | "test": "value" 61 | } 62 | ### get, auth with api key (query string) 63 | # A GET request with API key authentication (sent as query string). 64 | GET https://httpbin.org/anything?key=my_secret_key 65 | x-test: the_value 66 | { 67 | "test": "value" 68 | } 69 | 70 | # End of httpbin 71 | -------------------------------------------------------------------------------- /tests/verb.org: -------------------------------------------------------------------------------- 1 | * httpbin :verb: 2 | # A collection to test with httpbin: 3 | # - HTTP methods 4 | # - Authentication 5 | # - Anything. 6 | 7 | ** http_methods 8 | *** delete 9 | # A DELETE request. 10 | delete {{(verb-var url)}}/delete?search={{(verb-var variable_delete)}} 11 | x-test: the_value 12 | x-test2: second_value 13 | *** get 14 | # A GET request. 15 | get {{(verb-var url)}}/get?search={{(verb-var variable_get)}} 16 | x-test: the_value 17 | x-test2: second_value 18 | x-unknown: {{(verb-var unknown)}} 19 | *** patch 20 | # A PATCH request. 21 | patch {{(verb-var url)}}/patch?search=test 22 | x-test: the_value 23 | x-test2: second_value 24 | *** post 25 | # A POST request. 26 | post {{(verb-var url)}}/post?search=test 27 | x-test: the_value 28 | x-test2: second_value 29 | 30 | { 31 | "test": "value", 32 | "list": [ 33 | "first", 34 | "second" 35 | ], 36 | "var1": "{{(verb-var var1)}}" 37 | } 38 | *** put 39 | # A PUT request. 40 | put {{(verb-var url)}}/put?search=test 41 | x-test: the_value 42 | x-test2: second_value 43 | 44 | ** auth 45 | *** auth basic 46 | # A request with HTTP basic authentication. 47 | get {{(verb-var url)}}/basic-auth/user/secret 48 | Authorization: Basic {{(base64-encode-string (encode-coding-string "user:secret" 'utf-8) t)}} 49 | 50 | ** anything 51 | *** get, auth with api key (header) 52 | # A GET request with API key authentication (sent as HTTP header). 53 | get {{(verb-var url)}}/anything 54 | {{(verb-var header-api-key)}}: {{(verb-var api-key)}} 55 | x-test: the_value 56 | 57 | { 58 | "test": "value" 59 | } 60 | *** get, auth with api key (query string) 61 | # A GET request with API key authentication (sent as query string). 62 | get {{(verb-var url)}}/anything?{{(verb-var query-api-key)}}={{(verb-var api-key)}} 63 | x-test: the_value 64 | 65 | { 66 | "test": "value" 67 | } 68 | 69 | * End of httpbin 70 | 71 | # Local Variables: 72 | # eval: (verb-mode) 73 | # eval: (verb-set-var "var1" "value1_collection") 74 | # eval: (verb-set-var "url" "https://httpbin.org") 75 | # eval: (verb-set-var "variable_delete" "value_delete") 76 | # eval: (verb-set-var "variable_get" "value_get") 77 | # eval: (verb-set-var "header-api-key" "x-api-key") 78 | # eval: (verb-set-var "query-api-key" "key") 79 | # eval: (verb-set-var "api-key" "my_secret_key") 80 | # eval: (verb-set-var "var1" "value1_env") 81 | # End: 82 | -------------------------------------------------------------------------------- /tests/verb_no_vars.org: -------------------------------------------------------------------------------- 1 | * httpbin :verb: 2 | # A collection to test with httpbin: 3 | # - HTTP methods 4 | # - Authentication 5 | # - Anything. 6 | 7 | ** http_methods 8 | *** delete 9 | # A DELETE request. 10 | delete https://httpbin.org/delete?search=value_delete 11 | x-test: the_value 12 | x-test2: second_value 13 | *** get 14 | # A GET request. 15 | get https://httpbin.org/get?search=value_get 16 | x-test: the_value 17 | x-test2: second_value 18 | x-unknown: unknown 19 | *** patch 20 | # A PATCH request. 21 | patch https://httpbin.org/patch?search=test 22 | x-test: the_value 23 | x-test2: second_value 24 | *** post 25 | # A POST request. 26 | post https://httpbin.org/post?search=test 27 | x-test: the_value 28 | x-test2: second_value 29 | 30 | { 31 | "test": "value", 32 | "list": [ 33 | "first", 34 | "second" 35 | ], 36 | "var1": "value1_env" 37 | } 38 | *** put 39 | # A PUT request. 40 | put https://httpbin.org/put?search=test 41 | x-test: the_value 42 | x-test2: second_value 43 | 44 | ** auth 45 | *** auth basic 46 | # A request with HTTP basic authentication. 47 | get https://httpbin.org/basic-auth/user/secret 48 | Authorization: Basic {{(base64-encode-string (encode-coding-string "user:secret" 'utf-8) t)}} 49 | 50 | ** anything 51 | *** get, auth with api key (header) 52 | # A GET request with API key authentication (sent as HTTP header). 53 | get https://httpbin.org/anything 54 | x-api-key: my_secret_key 55 | x-test: the_value 56 | 57 | { 58 | "test": "value" 59 | } 60 | *** get, auth with api key (query string) 61 | # A GET request with API key authentication (sent as query string). 62 | get https://httpbin.org/anything?key=my_secret_key 63 | x-test: the_value 64 | 65 | { 66 | "test": "value" 67 | } 68 | 69 | * End of httpbin 70 | 71 | # Local Variables: 72 | # eval: (verb-mode) 73 | # End: 74 | --------------------------------------------------------------------------------