upnp_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package upnp
  16. import (
  17. "encoding/xml"
  18. "testing"
  19. )
  20. func TestExternalIPParsing(t *testing.T) {
  21. soap_response :=
  22. []byte(`<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  23. <s:Body>
  24. <u:GetExternalIPAddressResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
  25. <NewExternalIPAddress>1.2.3.4</NewExternalIPAddress>
  26. </u:GetExternalIPAddressResponse>
  27. </s:Body>
  28. </s:Envelope>`)
  29. envelope := &soapGetExternalIPAddressResponseEnvelope{}
  30. err := xml.Unmarshal(soap_response, envelope)
  31. if err != nil {
  32. t.Error(err)
  33. }
  34. if envelope.Body.GetExternalIPAddressResponse.NewExternalIPAddress != "1.2.3.4" {
  35. t.Error("Parse of SOAP request failed.")
  36. }
  37. }