|
| 1 | +/* |
| 2 | + * Copyright (C) 2020 Bosch.IO GmbH |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + * SPDX-License-Identifier: Apache-2.0 |
| 17 | + * License-Filename: LICENSE |
| 18 | + */ |
| 19 | + |
| 20 | +package org.ossreviewtoolkit.utils |
| 21 | + |
| 22 | +import io.kotest.core.spec.style.WordSpec |
| 23 | +import io.kotest.matchers.shouldBe |
| 24 | +import io.kotest.matchers.shouldNotBe |
| 25 | + |
| 26 | +class OrtAuthenticatorTest : WordSpec({ |
| 27 | + "getNetrcAuthentication()" should { |
| 28 | + "correctly parse single-line contents" { |
| 29 | + val authentication = getNetrcAuthentication(""" |
| 30 | + machine github.com login foo password bar |
| 31 | + """.trimIndent(), "github.com") |
| 32 | + |
| 33 | + authentication shouldNotBe null |
| 34 | + authentication!!.userName shouldBe "foo" |
| 35 | + authentication.password shouldBe "bar".toCharArray() |
| 36 | + } |
| 37 | + |
| 38 | + "correctly parse multi-line contents" { |
| 39 | + val authentication = getNetrcAuthentication(""" |
| 40 | + machine gitlab.com |
| 41 | + login foo |
| 42 | + password bar |
| 43 | + """.trimIndent(), "gitlab.com") |
| 44 | + |
| 45 | + authentication shouldNotBe null |
| 46 | + authentication!!.userName shouldBe "foo" |
| 47 | + authentication.password shouldBe "bar".toCharArray() |
| 48 | + } |
| 49 | + |
| 50 | + "recognize the default machine" { |
| 51 | + val authentication = getNetrcAuthentication(""" |
| 52 | + machine github.com |
| 53 | + login git |
| 54 | + password hub |
| 55 | + default login foo password bar |
| 56 | + """.trimIndent(), "gitlab.com") |
| 57 | + |
| 58 | + authentication shouldNotBe null |
| 59 | + authentication!!.userName shouldBe "foo" |
| 60 | + authentication.password shouldBe "bar".toCharArray() |
| 61 | + } |
| 62 | + |
| 63 | + "ignore superfluous statements" { |
| 64 | + val authentication = getNetrcAuthentication(""" |
| 65 | + machine "# A funky way to add comments." |
| 66 | + login funkyLogin |
| 67 | + password funkyPassword |
| 68 | + machine bitbucket.com |
| 69 | + # This is a port. |
| 70 | + port 433 |
| 71 | + password bar |
| 72 | + login foo |
| 73 | + """.trimIndent(), "bitbucket.com") |
| 74 | + |
| 75 | + authentication shouldNotBe null |
| 76 | + authentication!!.userName shouldBe "foo" |
| 77 | + authentication.password shouldBe "bar".toCharArray() |
| 78 | + } |
| 79 | + |
| 80 | + "ignore irrelavant machines" { |
| 81 | + val authentication = getNetrcAuthentication(""" |
| 82 | + machine bitbucket.com login foo password bar |
| 83 | + """.trimIndent(), "github.com") |
| 84 | + |
| 85 | + authentication shouldBe null |
| 86 | + } |
| 87 | + } |
| 88 | +}) |
0 commit comments