installck.pl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl -wnT
  2. use LWP 5.66; #
  3. use File::Basename;
  4. use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
  5. #
  6. # Script to check for the presence of install.js in Plugin XPIs
  7. # Should be run from the command line with a line like:
  8. #
  9. # ./installck file_containing_list_of_plugin_urls
  10. #
  11. # the n flag in the perl line at top of file will cause the running
  12. # of the script below once for each line of the supplied file.
  13. my $TMP_PREFIX = "tmp"; # prefix we prepend to XPIs when we download them
  14. # should choose so we don't overwrite anything useful in current dir.
  15. my $ua = LWP::UserAgent->new;
  16. my $url = $_;
  17. my $test_failed = 0;
  18. chop($url);
  19. print "\n\nURL is: $url\n";
  20. #
  21. # if possible extract the name of the XPI from the currently supplied URL
  22. #
  23. if ($url =~ m/.*\/(.*.xpi)/) {
  24. $fname = $TMP_PREFIX.$1; #set up tmp filename we will download to
  25. print "URL format test .... [PASSED]\n";
  26. } else {
  27. print "URL format test .... [FAILED]\n";
  28. print "Remaining tests .... [SKIPPED]\n";
  29. next;
  30. }
  31. #
  32. # try to download the XPI in question
  33. #
  34. my $response = $ua->get($url, ':content_file' => $fname);
  35. print "GET request status ".$response->status_line.", so test .... ";
  36. if($response->is_success) {
  37. print "[PASSED]\n";
  38. } else {
  39. print "[FAILED]\n";
  40. $test_failed = 1;
  41. }
  42. #
  43. # try to read the XPI archive
  44. #
  45. my $xpi = Archive::Zip->new();
  46. if($test_failed) {
  47. print "Read XPI test .... [SKIPPED]\n";
  48. } elsif ($xpi->read( $fname ) == AZ_OK ) {
  49. print "Read XPI test .... [PASSED]\n";
  50. } else {
  51. print "Read XPI test .... [FAILED]\n";
  52. $test_failed = 1;
  53. }
  54. #
  55. # Check XPI Archive for install.js file
  56. #
  57. if($test_failed) {
  58. print "Contains install.js check ... [SKIPPED]\n";
  59. } elsif ($xpi->memberNamed("install.js")) {
  60. print "Contains install.js check .... [FILE PRESENT]\n";
  61. } else {
  62. print "Contains install.js check .... [FILE NOT PRESENT]\n";
  63. }
  64. #
  65. # Clean up tmp file
  66. #
  67. unlink($fname);