Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
S
stats-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneurs
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
stats-facil
Validations
6db23447
Valider
6db23447
rédigé
11 years ago
par
Benaka Moorthi
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Fix maxmind downloading mechanism.
parent
a2d24124
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
plugins/UserCountry/GeoIPAutoUpdater.php
+23
-4
23 ajouts, 4 suppressions
plugins/UserCountry/GeoIPAutoUpdater.php
tests/PHPUnit/Plugins/UserCountryTest.php
+36
-3
36 ajouts, 3 suppressions
tests/PHPUnit/Plugins/UserCountryTest.php
avec
59 ajouts
et
7 suppressions
plugins/UserCountry/GeoIPAutoUpdater.php
+
23
−
4
Voir le fichier @
6db23447
...
@@ -84,7 +84,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater
...
@@ -84,7 +84,7 @@ class Piwik_UserCountry_GeoIPAutoUpdater
* from this URL.
* from this URL.
* @throws Exception
* @throws Exception
*/
*/
pr
ivate
function
downloadFile
(
$dbType
,
$url
)
pr
otected
function
downloadFile
(
$dbType
,
$url
)
{
{
$ext
=
Piwik_UserCountry_GeoIPAutoUpdater
::
getGeoIPUrlExtension
(
$url
);
$ext
=
Piwik_UserCountry_GeoIPAutoUpdater
::
getGeoIPUrlExtension
(
$url
);
$zippedFilename
=
Piwik_UserCountry_LocationProvider_GeoIp
::
$dbNames
[
$dbType
][
0
]
.
'.'
.
$ext
;
$zippedFilename
=
Piwik_UserCountry_LocationProvider_GeoIp
::
$dbNames
[
$dbType
][
0
]
.
'.'
.
$ext
;
...
@@ -421,15 +421,34 @@ class Piwik_UserCountry_GeoIPAutoUpdater
...
@@ -421,15 +421,34 @@ class Piwik_UserCountry_GeoIPAutoUpdater
{
{
// check for &suffix= query param that is special to MaxMind URLs
// check for &suffix= query param that is special to MaxMind URLs
if
(
preg_match
(
'/suffix=([^&]+)/'
,
$url
,
$matches
))
{
if
(
preg_match
(
'/suffix=([^&]+)/'
,
$url
,
$matches
))
{
return
$matches
[
1
];
$ext
=
$matches
[
1
];
}
}
// use basename of url
// use basename of url
$filenameParts
=
explode
(
'.'
,
basename
(
$url
),
2
);
$filenameParts
=
explode
(
'.'
,
basename
(
$url
),
2
);
if
(
count
(
$filenameParts
)
>
1
)
{
if
(
count
(
$filenameParts
)
>
1
)
{
return
end
(
$filenameParts
);
$ext
=
end
(
$filenameParts
);
}
else
{
}
else
{
return
reset
(
$filenameParts
);
$ext
=
reset
(
$filenameParts
);
}
self
::
checkForSupportedArchiveType
(
$ext
);
return
$ext
;
}
/**
* Avoid downloading archive types we don't support. No point in downloading it,
* if we can't unzip it...
*
* @param string $ext The URL file's extension.
*/
private
static
function
checkForSupportedArchiveType
(
$ext
)
{
if
(
$ext
!=
'tar.gz'
&&
$ext
!=
'gz'
)
{
throw
new
Exception
(
Piwik_Translate
(
'UserCountry_UnsupportedArchiveType'
,
"'
$ext
'"
));
}
}
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
tests/PHPUnit/Plugins/UserCountryTest.php
+
36
−
3
Voir le fichier @
6db23447
...
@@ -69,7 +69,12 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
...
@@ -69,7 +69,12 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
}
}
}
}
// test that redundant checks work
/**
* Test that redundant checks work.
*
* @group Plugins
* @group UserCountry
*/
public
function
testGeoIpUpdaterRedundantChecks
()
public
function
testGeoIpUpdaterRedundantChecks
()
{
{
Piwik_UserCountry_LocationProvider_GeoIp
::
$geoIPDatabaseDir
=
'tests/lib/geoip-files'
;
Piwik_UserCountry_LocationProvider_GeoIp
::
$geoIPDatabaseDir
=
'tests/lib/geoip-files'
;
...
@@ -79,7 +84,7 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
...
@@ -79,7 +84,7 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
$this
->
createEmptyISPOrgFiles
();
$this
->
createEmptyISPOrgFiles
();
// run redundant checks
// run redundant checks
$updater
=
new
Piwik_UserCountry_GeoIPAutoUpdater_publictest
RedundantChecks
();
$updater
=
new
Piwik_UserCountry_GeoIPAutoUpdater_publictest
();
$updater
->
performRedundantDbChecks
();
$updater
->
performRedundantDbChecks
();
// check that files are renamed correctly
// check that files are renamed correctly
...
@@ -93,6 +98,29 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
...
@@ -93,6 +98,29 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
$this
->
checkBrokenGeoIPState
();
$this
->
checkBrokenGeoIPState
();
}
}
/**
* @group Plugins
* @group UserCountry
* @dataProvider getInvalidGeoIpUrlsToTest
*/
public
function
testGeoIpDownloadInvalidUrl
(
$url
)
{
$updater
=
new
Piwik_UserCountry_GeoIPAutoUpdater_publictest
();
try
{
$updater
->
downloadFile
(
'loc'
,
$url
);
$this
->
fail
(
"Downloading invalid url succeeded!"
);
}
catch
(
Exception
$ex
)
{
$this
->
assertEquals
(
"UserCountry_UnsupportedArchiveType"
,
$ex
->
getMessage
());
}
}
public
function
getInvalidGeoIpUrlsToTest
()
{
return
array
(
array
(
"http://localhost/tests/resources/geoip.tar"
),
array
(
"http://localhost/tests/resources/geoip.tar.bz2"
),
array
(
"http://localhost/tests/resources/geoip.dat"
));
}
public
function
setUp
()
public
function
setUp
()
{
{
Piwik
::
$shouldLog
=
null
;
Piwik
::
$shouldLog
=
null
;
...
@@ -136,10 +164,15 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
...
@@ -136,10 +164,15 @@ class Test_Piwik_UserCountry extends PHPUnit_Framework_Testcase
}
}
}
}
class
Piwik_UserCountry_GeoIPAutoUpdater_publictest
RedundantChecks
extends
Piwik_UserCountry_GeoIPAutoUpdater
class
Piwik_UserCountry_GeoIPAutoUpdater_publictest
extends
Piwik_UserCountry_GeoIPAutoUpdater
{
{
public
function
performRedundantDbChecks
()
public
function
performRedundantDbChecks
()
{
{
parent
::
performRedundantDbChecks
();
parent
::
performRedundantDbChecks
();
}
}
public
function
downloadFile
(
$type
,
$url
)
{
parent
::
downloadFile
(
$type
,
$url
);
}
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter