OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
967 stars 177 forks source link

test: httpAddrGetList(webtest): FAIL #858

Closed eaglegai closed 6 months ago

eaglegai commented 6 months ago

Describe the bug since https://github.com/OpenPrinting/cups/commit/bd31658d04ed320fd6e8b2896f6997c37fbb3ee0, it will make hostname from uppercase to lowercase. cups version: 2.4.7

for example, my hostname is "WebTest", in testcase httpGetHostname, host->h_name is "WebTest", after _cups_tolower, httpGetHostname return "webtest" as hostname. then in the next testcase httpAddrGetList(testhttp.c)

   // httpGetHostname()
    testBegin("httpGetHostname()");

    if (httpGetHostname(NULL, hostname, sizeof(hostname)))
      testEndMessage(true, "%s", hostname);
    else
    {
      failures ++;
      testEnd(false);
    }

    // httpAddrGetList()
    testBegin("httpAddrGetList(%s)", hostname);

    addrlist = httpAddrGetList(hostname, AF_UNSPEC, NULL);
    if (addrlist)
    {
      for (i = 0, addr = addrlist; addr; i ++, addr = addr->next)
      {
        char    numeric[1024];      // Numeric IP address

    httpAddrGetString(&(addr->addr), numeric, sizeof(numeric));
    if (!strcmp(numeric, "UNKNOWN"))
      break;
      }

      if (addr)
        testEndMessage(false, "bad address for %s", hostname);
      else
        testEndMessage(true, "%d address(es) for %s", i, hostname);

      httpAddrFreeList(addrlist);
    }
    else if (isdigit(hostname[0] & 255))
    {
      testEndMessage(false, "ignored because hostname is numeric");
    }
    else
    {
      failures ++;
      testEnd(false);
    }

httpAddrGetList use "webtest" as the first argument, then getaddrinfo return -2 who use "webtest" as hostname, if use "WebTest", getaddrinfo will work well.

       }
    }

    if ((error = getaddrinfo(hostname, service, &hints, &results)) == 0)
    {
     /*
      * Copy the results to our own address list structure...
      */

so bd31658d is really necessary? if yes, if we should improve the testcase or do anything else to avoid httpAddrGetList testcase from failing ?

https://github.com/OpenPrinting/cups/issues/723 also have the same problems.

To Reproduce Steps to reproduce the behavior:

  1. hostname with uppercase
  2. build cups

Expected behavior build and tests success.

michaelrsweet commented 6 months ago

So hostnames are case-insensitive, so if changing the case of the name breaks things then that is a bug in the resolver on your system. It might also be a configuration setting...

eaglegai commented 6 months ago

dns is case-insensitive, but getaddrinfo which is provided by glibc(my version is 2.38) is case-sensitive, maybe in tests, httpAddrGetList shouldn't use the hostname given by httpGetHostname. Next, I will lookup glibc code.

michaelrsweet commented 6 months ago

Yeah, that doesn't make any sense for glibc to treat hostnames as case-sensitive.

zdohnal commented 6 months ago

It does not sound as CUPS bug for me either, so I'll close the issue for now. @eaglegai in case you find out the cause is really in CUPS, do let us know.

Thank you for reporting the issue nevertheless!