|
| 1 | +package rpm |
| 2 | + |
| 3 | +import ( |
| 4 | + "io/ioutil" |
| 5 | + "reflect" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/knqyf263/fanal/analyzer" |
| 9 | +) |
| 10 | + |
| 11 | +func TestParseRpmInfo(t *testing.T) { |
| 12 | + var tests = map[string]struct { |
| 13 | + path string |
| 14 | + pkgs []analyzer.Package |
| 15 | + }{ |
| 16 | + "Valid": { |
| 17 | + path: "./testdata/valid", |
| 18 | + pkgs: []analyzer.Package{ |
| 19 | + {Name: "centos-release", Version: "7", Release: "1.1503.el7.centos.2.8"}, |
| 20 | + {Name: "filesystem", Version: "3.2", Release: "18.el7"}, |
| 21 | + }, |
| 22 | + }, |
| 23 | + "ValidBig": { |
| 24 | + path: "./testdata/valid_big", |
| 25 | + pkgs: []analyzer.Package{ |
| 26 | + {Name: "publicsuffix-list-dafsa", Epoch: 0, Version: "20180514", Release: "1.fc28"}, |
| 27 | + {Name: "libreport-filesystem", Epoch: 0, Version: "2.9.5", Release: "1.fc28"}, |
| 28 | + {Name: "fedora-gpg-keys", Epoch: 0, Version: "28", Release: "5"}, |
| 29 | + {Name: "fedora-release", Epoch: 0, Version: "28", Release: "2"}, |
| 30 | + {Name: "filesystem", Epoch: 0, Version: "3.8", Release: "2.fc28"}, |
| 31 | + {Name: "tzdata", Epoch: 0, Version: "2018e", Release: "1.fc28"}, |
| 32 | + {Name: "pcre2", Epoch: 0, Version: "10.31", Release: "10.fc28"}, |
| 33 | + {Name: "glibc-minimal-langpack", Epoch: 0, Version: "2.27", Release: "32.fc28"}, |
| 34 | + {Name: "glibc-common", Epoch: 0, Version: "2.27", Release: "32.fc28"}, |
| 35 | + {Name: "bash", Epoch: 0, Version: "4.4.23", Release: "1.fc28"}, |
| 36 | + {Name: "zlib", Epoch: 0, Version: "1.2.11", Release: "8.fc28"}, |
| 37 | + {Name: "bzip2-libs", Epoch: 0, Version: "1.0.6", Release: "26.fc28"}, |
| 38 | + {Name: "libcap", Epoch: 0, Version: "2.25", Release: "9.fc28"}, |
| 39 | + {Name: "libgpg-error", Epoch: 0, Version: "1.31", Release: "1.fc28"}, |
| 40 | + {Name: "libzstd", Epoch: 0, Version: "1.3.5", Release: "1.fc28"}, |
| 41 | + {Name: "expat", Epoch: 0, Version: "2.2.5", Release: "3.fc28"}, |
| 42 | + {Name: "nss-util", Epoch: 0, Version: "3.38.0", Release: "1.0.fc28"}, |
| 43 | + {Name: "libcom_err", Epoch: 0, Version: "1.44.2", Release: "0.fc28"}, |
| 44 | + {Name: "libffi", Epoch: 0, Version: "3.1", Release: "16.fc28"}, |
| 45 | + {Name: "libgcrypt", Epoch: 0, Version: "1.8.3", Release: "1.fc28"}, |
| 46 | + {Name: "libxml2", Epoch: 0, Version: "2.9.8", Release: "4.fc28"}, |
| 47 | + {Name: "libacl", Epoch: 0, Version: "2.2.53", Release: "1.fc28"}, |
| 48 | + {Name: "sed", Epoch: 0, Version: "4.5", Release: "1.fc28"}, |
| 49 | + {Name: "libmount", Epoch: 0, Version: "2.32.1", Release: "1.fc28"}, |
| 50 | + {Name: "p11-kit", Epoch: 0, Version: "0.23.12", Release: "1.fc28"}, |
| 51 | + {Name: "libidn2", Epoch: 0, Version: "2.0.5", Release: "1.fc28"}, |
| 52 | + {Name: "libcap-ng", Epoch: 0, Version: "0.7.9", Release: "4.fc28"}, |
| 53 | + {Name: "lz4-libs", Epoch: 0, Version: "1.8.1.2", Release: "4.fc28"}, |
| 54 | + {Name: "libassuan", Epoch: 0, Version: "2.5.1", Release: "3.fc28"}, |
| 55 | + {Name: "keyutils-libs", Epoch: 0, Version: "1.5.10", Release: "6.fc28"}, |
| 56 | + {Name: "glib2", Epoch: 0, Version: "2.56.1", Release: "4.fc28"}, |
| 57 | + {Name: "systemd-libs", Epoch: 0, Version: "238", Release: "9.git0e0aa59.fc28"}, |
| 58 | + {Name: "dbus-libs", Epoch: 1, Version: "1.12.10", Release: "1.fc28"}, |
| 59 | + {Name: "libtasn1", Epoch: 0, Version: "4.13", Release: "2.fc28"}, |
| 60 | + {Name: "ca-certificates", Epoch: 0, Version: "2018.2.24", Release: "1.0.fc28"}, |
| 61 | + {Name: "libarchive", Epoch: 0, Version: "3.3.1", Release: "4.fc28"}, |
| 62 | + {Name: "openssl", Epoch: 1, Version: "1.1.0h", Release: "3.fc28"}, |
| 63 | + {Name: "libusbx", Epoch: 0, Version: "1.0.22", Release: "1.fc28"}, |
| 64 | + {Name: "libsemanage", Epoch: 0, Version: "2.8", Release: "2.fc28"}, |
| 65 | + {Name: "libutempter", Epoch: 0, Version: "1.1.6", Release: "14.fc28"}, |
| 66 | + {Name: "mpfr", Epoch: 0, Version: "3.1.6", Release: "1.fc28"}, |
| 67 | + {Name: "gnutls", Epoch: 0, Version: "3.6.3", Release: "4.fc28"}, |
| 68 | + {Name: "gzip", Epoch: 0, Version: "1.9", Release: "3.fc28"}, |
| 69 | + {Name: "acl", Epoch: 0, Version: "2.2.53", Release: "1.fc28"}, |
| 70 | + {Name: "nss-softokn-freebl", Epoch: 0, Version: "3.38.0", Release: "1.0.fc28"}, |
| 71 | + {Name: "nss", Epoch: 0, Version: "3.38.0", Release: "1.0.fc28"}, |
| 72 | + {Name: "libmetalink", Epoch: 0, Version: "0.1.3", Release: "6.fc28"}, |
| 73 | + {Name: "libdb-utils", Epoch: 0, Version: "5.3.28", Release: "30.fc28"}, |
| 74 | + {Name: "file-libs", Epoch: 0, Version: "5.33", Release: "7.fc28"}, |
| 75 | + {Name: "libsss_idmap", Epoch: 0, Version: "1.16.3", Release: "2.fc28"}, |
| 76 | + {Name: "libsigsegv", Epoch: 0, Version: "2.11", Release: "5.fc28"}, |
| 77 | + {Name: "krb5-libs", Epoch: 0, Version: "1.16.1", Release: "13.fc28"}, |
| 78 | + {Name: "libnsl2", Epoch: 0, Version: "1.2.0", Release: "2.20180605git4a062cf.fc28"}, |
| 79 | + {Name: "python3-pip", Epoch: 0, Version: "9.0.3", Release: "2.fc28"}, |
| 80 | + {Name: "python3", Epoch: 0, Version: "3.6.6", Release: "1.fc28"}, |
| 81 | + {Name: "pam", Epoch: 0, Version: "1.3.1", Release: "1.fc28"}, |
| 82 | + {Name: "python3-gobject-base", Epoch: 0, Version: "3.28.3", Release: "1.fc28"}, |
| 83 | + {Name: "python3-smartcols", Epoch: 0, Version: "0.3.0", Release: "2.fc28"}, |
| 84 | + {Name: "python3-iniparse", Epoch: 0, Version: "0.4", Release: "30.fc28"}, |
| 85 | + {Name: "openldap", Epoch: 0, Version: "2.4.46", Release: "3.fc28"}, |
| 86 | + {Name: "libseccomp", Epoch: 0, Version: "2.3.3", Release: "2.fc28"}, |
| 87 | + {Name: "npth", Epoch: 0, Version: "1.5", Release: "4.fc28"}, |
| 88 | + {Name: "gpgme", Epoch: 0, Version: "1.10.0", Release: "4.fc28"}, |
| 89 | + {Name: "json-c", Epoch: 0, Version: "0.13.1", Release: "2.fc28"}, |
| 90 | + {Name: "libyaml", Epoch: 0, Version: "0.1.7", Release: "5.fc28"}, |
| 91 | + {Name: "libpkgconf", Epoch: 0, Version: "1.4.2", Release: "1.fc28"}, |
| 92 | + {Name: "pkgconf-pkg-config", Epoch: 0, Version: "1.4.2", Release: "1.fc28"}, |
| 93 | + {Name: "iptables-libs", Epoch: 0, Version: "1.6.2", Release: "3.fc28"}, |
| 94 | + {Name: "device-mapper-libs", Epoch: 0, Version: "1.02.146", Release: "5.fc28"}, |
| 95 | + {Name: "systemd-pam", Epoch: 0, Version: "238", Release: "9.git0e0aa59.fc28"}, |
| 96 | + {Name: "systemd", Epoch: 0, Version: "238", Release: "9.git0e0aa59.fc28"}, |
| 97 | + {Name: "elfutils-default-yama-scope", Epoch: 0, Version: "0.173", Release: "1.fc28"}, |
| 98 | + {Name: "libcurl", Epoch: 0, Version: "7.59.0", Release: "6.fc28"}, |
| 99 | + {Name: "python3-librepo", Epoch: 0, Version: "1.8.1", Release: "7.fc28"}, |
| 100 | + {Name: "rpm-plugin-selinux", Epoch: 0, Version: "4.14.1", Release: "9.fc28"}, |
| 101 | + {Name: "rpm", Epoch: 0, Version: "4.14.1", Release: "9.fc28"}, |
| 102 | + {Name: "libdnf", Epoch: 0, Version: "0.11.1", Release: "3.fc28"}, |
| 103 | + {Name: "rpm-build-libs", Epoch: 0, Version: "4.14.1", Release: "9.fc28"}, |
| 104 | + {Name: "python3-rpm", Epoch: 0, Version: "4.14.1", Release: "9.fc28"}, |
| 105 | + {Name: "dnf", Epoch: 0, Version: "2.7.5", Release: "12.fc28"}, |
| 106 | + {Name: "deltarpm", Epoch: 0, Version: "3.6", Release: "25.fc28"}, |
| 107 | + {Name: "sssd-client", Epoch: 0, Version: "1.16.3", Release: "2.fc28"}, |
| 108 | + {Name: "cracklib-dicts", Epoch: 0, Version: "2.9.6", Release: "13.fc28"}, |
| 109 | + {Name: "tar", Epoch: 2, Version: "1.30", Release: "3.fc28"}, |
| 110 | + {Name: "diffutils", Epoch: 0, Version: "3.6", Release: "4.fc28"}, |
| 111 | + {Name: "langpacks-en", Epoch: 0, Version: "1.0", Release: "12.fc28"}, |
| 112 | + {Name: "gpg-pubkey", Epoch: 0, Version: "9db62fb1", Release: "59920156"}, |
| 113 | + {Name: "libgcc", Epoch: 0, Version: "8.1.1", Release: "5.fc28"}, |
| 114 | + {Name: "pkgconf-m4", Epoch: 0, Version: "1.4.2", Release: "1.fc28"}, |
| 115 | + {Name: "dnf-conf", Epoch: 0, Version: "2.7.5", Release: "12.fc28"}, |
| 116 | + {Name: "fedora-repos", Epoch: 0, Version: "28", Release: "5"}, |
| 117 | + {Name: "setup", Epoch: 0, Version: "2.11.4", Release: "1.fc28"}, |
| 118 | + {Name: "basesystem", Epoch: 0, Version: "11", Release: "5.fc28"}, |
| 119 | + {Name: "ncurses-base", Epoch: 0, Version: "6.1", Release: "5.20180224.fc28"}, |
| 120 | + {Name: "libselinux", Epoch: 0, Version: "2.8", Release: "1.fc28"}, |
| 121 | + {Name: "ncurses-libs", Epoch: 0, Version: "6.1", Release: "5.20180224.fc28"}, |
| 122 | + {Name: "glibc", Epoch: 0, Version: "2.27", Release: "32.fc28"}, |
| 123 | + {Name: "libsepol", Epoch: 0, Version: "2.8", Release: "1.fc28"}, |
| 124 | + {Name: "xz-libs", Epoch: 0, Version: "5.2.4", Release: "2.fc28"}, |
| 125 | + {Name: "info", Epoch: 0, Version: "6.5", Release: "4.fc28"}, |
| 126 | + {Name: "libdb", Epoch: 0, Version: "5.3.28", Release: "30.fc28"}, |
| 127 | + {Name: "elfutils-libelf", Epoch: 0, Version: "0.173", Release: "1.fc28"}, |
| 128 | + {Name: "popt", Epoch: 0, Version: "1.16", Release: "14.fc28"}, |
| 129 | + {Name: "nspr", Epoch: 0, Version: "4.19.0", Release: "1.fc28"}, |
| 130 | + {Name: "libxcrypt", Epoch: 0, Version: "4.1.2", Release: "1.fc28"}, |
| 131 | + {Name: "lua-libs", Epoch: 0, Version: "5.3.4", Release: "10.fc28"}, |
| 132 | + {Name: "libuuid", Epoch: 0, Version: "2.32.1", Release: "1.fc28"}, |
| 133 | + {Name: "readline", Epoch: 0, Version: "7.0", Release: "11.fc28"}, |
| 134 | + {Name: "libattr", Epoch: 0, Version: "2.4.48", Release: "3.fc28"}, |
| 135 | + {Name: "coreutils-single", Epoch: 0, Version: "8.29", Release: "7.fc28"}, |
| 136 | + {Name: "libblkid", Epoch: 0, Version: "2.32.1", Release: "1.fc28"}, |
| 137 | + {Name: "gmp", Epoch: 1, Version: "6.1.2", Release: "7.fc28"}, |
| 138 | + {Name: "libunistring", Epoch: 0, Version: "0.9.10", Release: "1.fc28"}, |
| 139 | + {Name: "sqlite-libs", Epoch: 0, Version: "3.22.0", Release: "4.fc28"}, |
| 140 | + {Name: "audit-libs", Epoch: 0, Version: "2.8.4", Release: "2.fc28"}, |
| 141 | + {Name: "chkconfig", Epoch: 0, Version: "1.10", Release: "4.fc28"}, |
| 142 | + {Name: "libsmartcols", Epoch: 0, Version: "2.32.1", Release: "1.fc28"}, |
| 143 | + {Name: "pcre", Epoch: 0, Version: "8.42", Release: "3.fc28"}, |
| 144 | + {Name: "grep", Epoch: 0, Version: "3.1", Release: "5.fc28"}, |
| 145 | + {Name: "crypto-policies", Epoch: 0, Version: "20180425", Release: "5.git6ad4018.fc28"}, |
| 146 | + {Name: "gdbm-libs", Epoch: 1, Version: "1.14.1", Release: "4.fc28"}, |
| 147 | + {Name: "p11-kit-trust", Epoch: 0, Version: "0.23.12", Release: "1.fc28"}, |
| 148 | + {Name: "openssl-libs", Epoch: 1, Version: "1.1.0h", Release: "3.fc28"}, |
| 149 | + {Name: "ima-evm-utils", Epoch: 0, Version: "1.1", Release: "2.fc28"}, |
| 150 | + {Name: "gdbm", Epoch: 1, Version: "1.14.1", Release: "4.fc28"}, |
| 151 | + {Name: "gobject-introspection", Epoch: 0, Version: "1.56.1", Release: "1.fc28"}, |
| 152 | + {Name: "shadow-utils", Epoch: 2, Version: "4.6", Release: "1.fc28"}, |
| 153 | + {Name: "libpsl", Epoch: 0, Version: "0.20.2", Release: "2.fc28"}, |
| 154 | + {Name: "nettle", Epoch: 0, Version: "3.4", Release: "2.fc28"}, |
| 155 | + {Name: "libfdisk", Epoch: 0, Version: "2.32.1", Release: "1.fc28"}, |
| 156 | + {Name: "cracklib", Epoch: 0, Version: "2.9.6", Release: "13.fc28"}, |
| 157 | + {Name: "libcomps", Epoch: 0, Version: "0.1.8", Release: "11.fc28"}, |
| 158 | + {Name: "nss-softokn", Epoch: 0, Version: "3.38.0", Release: "1.0.fc28"}, |
| 159 | + {Name: "nss-sysinit", Epoch: 0, Version: "3.38.0", Release: "1.0.fc28"}, |
| 160 | + {Name: "libksba", Epoch: 0, Version: "1.3.5", Release: "7.fc28"}, |
| 161 | + {Name: "kmod-libs", Epoch: 0, Version: "25", Release: "2.fc28"}, |
| 162 | + {Name: "libsss_nss_idmap", Epoch: 0, Version: "1.16.3", Release: "2.fc28"}, |
| 163 | + {Name: "libverto", Epoch: 0, Version: "0.3.0", Release: "5.fc28"}, |
| 164 | + {Name: "gawk", Epoch: 0, Version: "4.2.1", Release: "1.fc28"}, |
| 165 | + {Name: "libtirpc", Epoch: 0, Version: "1.0.3", Release: "3.rc2.fc28"}, |
| 166 | + {Name: "python3-libs", Epoch: 0, Version: "3.6.6", Release: "1.fc28"}, |
| 167 | + {Name: "python3-setuptools", Epoch: 0, Version: "39.2.0", Release: "6.fc28"}, |
| 168 | + {Name: "libpwquality", Epoch: 0, Version: "1.4.0", Release: "7.fc28"}, |
| 169 | + {Name: "util-linux", Epoch: 0, Version: "2.32.1", Release: "1.fc28"}, |
| 170 | + {Name: "python3-libcomps", Epoch: 0, Version: "0.1.8", Release: "11.fc28"}, |
| 171 | + {Name: "python3-six", Epoch: 0, Version: "1.11.0", Release: "3.fc28"}, |
| 172 | + {Name: "cyrus-sasl-lib", Epoch: 0, Version: "2.1.27", Release: "0.2rc7.fc28"}, |
| 173 | + {Name: "libssh", Epoch: 0, Version: "0.8.2", Release: "1.fc28"}, |
| 174 | + {Name: "qrencode-libs", Epoch: 0, Version: "3.4.4", Release: "5.fc28"}, |
| 175 | + {Name: "gnupg2", Epoch: 0, Version: "2.2.8", Release: "1.fc28"}, |
| 176 | + {Name: "python3-gpg", Epoch: 0, Version: "1.10.0", Release: "4.fc28"}, |
| 177 | + {Name: "libargon2", Epoch: 0, Version: "20161029", Release: "5.fc28"}, |
| 178 | + {Name: "libmodulemd", Epoch: 0, Version: "1.6.2", Release: "2.fc28"}, |
| 179 | + {Name: "pkgconf", Epoch: 0, Version: "1.4.2", Release: "1.fc28"}, |
| 180 | + {Name: "libpcap", Epoch: 14, Version: "1.9.0", Release: "1.fc28"}, |
| 181 | + {Name: "device-mapper", Epoch: 0, Version: "1.02.146", Release: "5.fc28"}, |
| 182 | + {Name: "cryptsetup-libs", Epoch: 0, Version: "2.0.4", Release: "1.fc28"}, |
| 183 | + {Name: "elfutils-libs", Epoch: 0, Version: "0.173", Release: "1.fc28"}, |
| 184 | + {Name: "dbus", Epoch: 1, Version: "1.12.10", Release: "1.fc28"}, |
| 185 | + {Name: "libnghttp2", Epoch: 0, Version: "1.32.1", Release: "1.fc28"}, |
| 186 | + {Name: "librepo", Epoch: 0, Version: "1.8.1", Release: "7.fc28"}, |
| 187 | + {Name: "curl", Epoch: 0, Version: "7.59.0", Release: "6.fc28"}, |
| 188 | + {Name: "rpm-libs", Epoch: 0, Version: "4.14.1", Release: "9.fc28"}, |
| 189 | + {Name: "libsolv", Epoch: 0, Version: "0.6.35", Release: "1.fc28"}, |
| 190 | + {Name: "python3-hawkey", Epoch: 0, Version: "0.11.1", Release: "3.fc28"}, |
| 191 | + {Name: "rpm-sign-libs", Epoch: 0, Version: "4.14.1", Release: "9.fc28"}, |
| 192 | + {Name: "python3-dnf", Epoch: 0, Version: "2.7.5", Release: "12.fc28"}, |
| 193 | + {Name: "dnf-yum", Epoch: 0, Version: "2.7.5", Release: "12.fc28"}, |
| 194 | + {Name: "rpm-plugin-systemd-inhibit", Epoch: 0, Version: "4.14.1", Release: "9.fc28"}, |
| 195 | + {Name: "nss-tools", Epoch: 0, Version: "3.38.0", Release: "1.0.fc28"}, |
| 196 | + {Name: "openssl-pkcs11", Epoch: 0, Version: "0.4.8", Release: "1.fc28"}, |
| 197 | + {Name: "vim-minimal", Epoch: 2, Version: "8.1.328", Release: "1.fc28"}, |
| 198 | + {Name: "glibc-langpack-en", Epoch: 0, Version: "2.27", Release: "32.fc28"}, |
| 199 | + {Name: "rootfiles", Epoch: 0, Version: "8.1", Release: "22.fc28"}, |
| 200 | + }, |
| 201 | + }, |
| 202 | + } |
| 203 | + a := rpmPkgAnalyzer{} |
| 204 | + for i, v := range tests { |
| 205 | + bytes, err := ioutil.ReadFile(v.path) |
| 206 | + if err != nil { |
| 207 | + t.Errorf("%s : can't open file %s", i, v.path) |
| 208 | + } |
| 209 | + pkgs, err := a.parsePkgInfo(bytes) |
| 210 | + if err != nil { |
| 211 | + t.Errorf("%s : catch the error : %v", i, err) |
| 212 | + } |
| 213 | + if !reflect.DeepEqual(v.pkgs, pkgs) { |
| 214 | + t.Errorf("[%s]\nexpected : %v\nactual : %v", i, v.pkgs, pkgs) |
| 215 | + } |
| 216 | + } |
| 217 | +} |
0 commit comments